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!
--]]
Are there any code examples left?
New code examples in category Lua
-
Lua 2022-03-27 16:30:01 how to use for iv in pairs
-
Lua 2022-03-27 15:10:08 lua last item in table
-
Lua 2022-03-27 07:10:05 how to make a table in lua
-
Lua 2022-03-25 05:45:17 function parameters roblox
-
Lua 2022-03-24 19:50:37 lua variables
-
Lua 2022-03-16 23:30:02 lua list of all keys
-
Lua 2022-03-16 21:40:31 play sound love2d
-
Lua 2022-03-12 11:15:06 how to get the player mouse in roblox studio
-
Lua 2022-03-12 09:40:17 how to add a damage decimal in roblox studio
-
Lua 2022-03-02 18:40:19 lowercase lua