Hey I want to make a part in my game that when you touch it, it moves 10 studs or so studs but I can’t figure it out. It may be more complicated than I first thought but I would still like to make it. Here is the code that I wrote, local Variable = (1)
Your original code splits the moving & touching into sections, instead you need to combine them.
You should instead try this:
-- You should know what this does ;)
game.Workspace.Egg.Touched:Connect(function(obj)
-- We need this to check if it's a player, not a random part or something
local player = game.Players:GetPlayerFromCharacter(obj.Parent)
if player then
-- Move it forward 10 studs on the X AXIS
game.Workspace.Egg.Position = game.Workspace.Egg.Position + Vector3.new(10, 0, 0)
end
end)
I wrote this quickly, so there might be some small mistakes/errors, so reply & let me know if it doesn’t work out.
Try making the Vector3.new(10, 0, 0) now Vector3.new(0, 10, 0) or fill in those numbers with anything and see what happens! The key to learning is experimenting.
When you do a touched event, obj (you can name it anything, I just use obj) is the thing that touched it.
X, Y, Z, because you are changing to Y, you are changing the height. The reason it keeps falling is because it is un-anchored, open the properties window, search “anchor” while selecting the part, and set it to true! This makes it so it doesn’t fall.