Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make this block moving script execute on GUI button press?

Asked by 2 years ago
Edited 2 years ago

I have a script to make a block move forward continuously. It works just fine. But I wanted to make a main menu with a play button. So therefor I had to make it so the block would start moving after the player pressed the button Play. I tried to script it but couldn't figure it out. Can someone help? Here is the script ~~~~~~~~~~~~~~~~~

game.StarterGui.ScreenGui.Frame.Play.MouseButton1Down:connect(function()
wait(7)
local distance = 20000

script.Parent.Anchored = true

for i = 0, distance do

end
script.Parent.CFrame = script.Parent.CFrame+Vector3.new(2.1,0,0)
wait(0.1)   

end)

~~~~~~~~~~~~~~~~~

1 answer

Log in to vote
0
Answered by 2 years ago

From the looks of it, you accidentally moved line 10 and 11 outside of the for loop, so adding those back in should fix it:

game.StarterGui.ScreenGui.Frame.Play.MouseButton1Down:connect(function()
    wait(7)
    local distance = 20000

    script.Parent.Anchored = true

    for i = 0, distance do
        script.Parent.CFrame = script.Parent.CFrame+Vector3.new(2.1,0,0)
        wait(0.1)
    end
end)

No shame in this though. It happens to the best of us!

0
Ah I see, convert the Script to a LocalScript. Scripts can't detect client events such as MouseButton1Down. efficacies 180 — 2y
0
I'm super super sorry for the bother, It still doesn't seem to be working.. If it's okay maybe we can find another way to do the script or fix this issue because i'm pretty clueless right now to be honest.. I changed it to a local script but still doesn't work.. The block doesn't even move TheEpicWaterBoss 0 — 2y
Ad

Answer this question