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

How to make an object stop following your mouse when you press a GUI button?

Im trying to have an object follow the mouse when i press a guibutton button and have it stop following it when i press the same button how can you get it to stop following it

The following part works fine but it wont stop following

here is my code currently:

local Player = game.Players.LocalPlayer
local HandTracer = workspace.HAND_TRACER
local mouse = Player:GetMouse()
local squishbutton = game.StarterGui.Human_GUI.Squish_button -- the button pressed

if Player.Team.TeamColor == BrickColor.new("New Yeller") then
	script.Parent.Parent.Enabled = true
	script.Parent.MouseButton1Click:Connect(function()
		if HandTracer.Transparency == 1 then
			HandTracer.Transparency = 0.65	
	mouse.TargetFilter = game.Workspace.HAND_TRACER

	while wait() do
		game.Workspace.HAND_TRACER.CFrame = CFrame.new(mouse.Hit.p)
		game.Workspace.HAND_TRACER.Orientation = Vector3.new(-90, 90, 0)
	end

		else
			HandTracer.Transparency = 1	
		end
	end)

end

if Player.Team.TeamColor == BrickColor.new("Black") then
script.Parent.Parent.Enabled = false
end

1 answer

instead of doing

while wait() do

add in the " HandTracer.Transparency == 0.65 " condition; therefore making it

while wait() and HandTracer.Transparency == 0.65 do

this way it'll stop the loop if the hand is invisible

3 comments

0

line 13*

0

Couldnt get it too work

0

its not following the mouse anymore

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