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

Place a block when you click?

I'm trying to make it so when you click a gui, a brick follows your mouse, and if you click again, the brick stops following your mouse. Why won't this work?

It's a localscript.

This is what I have:

player = game.Players.LocalPlayer
mouse = player:GetMouse()

function run()
	script.Parent.TestValue.Value = true
	
	local test = game.ReplicatedStorage.BuildItems.Test:clone()
	test.Parent = game.Workspace
		while true and script.Parent.TestValue.Value == true do
		wait()
		test.Position = Vector3.new(mouse.Hit.p.X,0.5,mouse.Hit.p.Z)
		mouse.Button1Down:connect(function()
			--script.Parent.TestValue.Value = false
			break -- something is wrong with this
		end)
		
	end
end

script.Parent.MouseButton1Down:connect(function()
	run()
end)

1 answer

✓ Accepted answer

Try using "return" instead of "break", cause return ends the function and break ends the loop

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