I'm Rain
I'm Rain

Reputation: 31

How to move created objects in Roblox

I am making a game in roblox studio and I need to make the object I created (created manually) move towards the player. Here is the code:

    local pl = game.Players.LocalPlayer
    local Money = script.Parent.Parent.Money
    Money.MoveTo(Vector3.new(player.Homeloc.Value))
    wait(5)

help me please

Upvotes: 0

Views: 3811

Answers (4)

Open Pees
Open Pees

Reputation: 13

I would recommend tweening the item with the player as the goal

what a tween would might look like:

local TweenService = game:GetService("TweenService")
local part = script.Parent

local Info = TweenInfo.new(
    5,           --seconds it takes to complete loop
    Enum.EasingStyle.Linear,     --easingstyle (how it moves)
    Enum.EasingDirection.InOut,    --easingdirection (which direction)
    -1,                    --times repeated (-1 = infinite)
    true,                 --reverse
    0                      --delay time
)
 

local Goals ={ --these are the goals of the tween
Position = game.Workspace.Baseplate.Position
}

 

local tween = TweenService:Create(part,Info,Goals)
tween:Play()

Upvotes: 0

DemoNemo5
DemoNemo5

Reputation: 182

If you want it to be a smooth, animated move, just put a BodyPosition inside the part, and in a script, set the Position to be the player's position:

Money.BodyPosition.Position = pl.Character.HumanoidRootPart.Position

Upvotes: 0

Glow Bunny
Glow Bunny

Reputation: 102

You put a . in Money.MoveTo(Vector3.new(player.Homeloc.Value)), the MoveTo is a function of a model so it has to be Money:MoveTo(Vector3.new(..))

Upvotes: 1

Piglet
Piglet

Reputation: 28950

What is wrong with following the example from the manual? https://developer.roblox.com/en-us/api-reference/function/Model/MoveTo

-- define two Positions
local startPosition = Vector3.new(-20, 10, 0)
local endPosition = Vector3.new(0, 10, 0)
 
-- create a simple model at the startPosition
local model = Instance.new("Model", game.Workspace)
 
local part1 = Instance.new("Part")
part1.Size = Vector3.new(4, 4, 4)
part1.Position = startPosition
part1.Anchored = true
part1.BrickColor = BrickColor.new("Bright yellow")
part1.Parent = model
 
local part2 = Instance.new("Part")
part2.Size = Vector3.new(2, 2, 2)
part2.Position = startPosition + Vector3.new(0, 3, 0)
part2.Anchored = true
part2.BrickColor = BrickColor.new("Bright blue")
part2.Parent = model
 
-- set the primary part
model.PrimaryPart = part1
model.Parent = game.Workspace
 
-- create an obstruction at the endPosition
local obstruction = Instance.new("Part")
obstruction.Name = "Obstruction"
obstruction.Size = Vector3.new(10, 10, 10)
obstruction.Position = Vector3.new(0, 10, 0)
obstruction.Anchored = true
obstruction.BrickColor = BrickColor.new("Bright green")
obstruction.Parent = game.Workspace
 
wait(3)
-- attempt to move the model to the obstructed endPosition
model:MoveTo(endPosition)

Simply searching the web for "Roblox move object" yields https://developer.roblox.com/en-us/articles/positioning-objects as a first hit for me. So if you're asking yourself how to move an object in Roblox this is probably a good place to start.

Upvotes: 0

Related Questions