So I’m experimenting with code, the code without being a function ALREADY WORKS, I am just trying to make it so when I click the button it will work.
Here is the code I used
local cheese = script.Parent
local Button = game.Workspace.Button.ClickDetector
local dir = 1
local function moveCheese()
while true do
cheese.Position = cheese.Position + Vector3.new(0,1*dir,0)
wait(.15)
if (cheese.Position.Y > 10) then
dir = -1
end
if (cheese.Position.Y < 5) then
dir = 1
end
end
end
Button.ClickDetector.MouseClicked:Connect(moveCheese)