Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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!

3 comments

0

Ah I see, convert the Script to a LocalScript. Scripts can't detect client events such as MouseButton1Down.

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

This discussion is preserved as it was. New answers, comments, and votes are closed.