Answers for "how to make an moving object in roblox"

Lua
0

how to make an moving object in roblox

--[[ Aiden's Smart Code, make sure to learn from this and use it later on!
But before you copy this code you will need to do a few things, such as:
1. Insert an BodyPosition in the object.
2. Make an script in the object.
3. Make sure the object is just under Workspace.

There are multiple codes in here so make sure to get the right code!
--]]

-- Code 1, when a player joins the game the object will move:

local Object = game.Workspace:WaitForChild("Object Name Here")
local BodyPosition = Object.BodyPosition

game.Players.PlayerAdded:Connect(function(player)
	BodyPosition.Position = Vector3.new(Coördinates in these brackets)
    -- Use this if you want the object to move to another position after this!
    wait(5) -- Change this number to how many seconds you want to wait.
    BodyPosition.Position = Vector3.new(Coördinates in these brackets)
end)

-- Code 2, when a player touches another object, the object will move:

local Object = game.Workspace:WaitForChild("Object Name Here")
local TouchedObject = game.Workspace:WaitForChild("Touched Object Name Here")
local BodyPosition = Object.BodyPosition

function OnTouched(part)
	BodyPosition.Position = Vector3.new(Coördinates in these brackets)
    -- Use this if you want the object to move to another position after this!
    wait(5)
    BodyPosition.Position = Vector3.new(Coördinates in these brackets)
end

TouchedObject.Touched:Connect(OnTouched)

--[[ This is all there is, i hope you will have learned from this code
and that you will use it soon in your games!

If you'd like to thank me you can do this:
1. Learn from this code and become a better programmer!
2. Like this code!
3. Make an successfull game!
--]]
Posted by: Guest on September-28-2020

Code answers related to "how to make an moving object in roblox"

Browse Popular Code Answers by Language