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

How do I stop this from working after I unequip it?

This is a tool that pulls things towards you when you click on them. My problem is that it keeps working even after I unequip the tool. How do I fix it?

player = game.Players.LocalPlayer
mouse = player:GetMouse()
local debounce = true


script.Parent.Equipped:Connect(function()
		mouse.Button1Down:connect(function()
			
			mouse.TargetFilter = game.Workspace:FindFirstChild("7")
			
	if debounce == true then
		if mouse.Target.Anchored == false and mouse.Target.Name == "Part" then
			
			
		local Sound = Instance.new("Sound", mouse.Target)
		Sound.SoundId = "rbxassetid://131526385"
		Sound.Volume = 1
		if not Sound.IsPlaying then
			Sound:Play()
		end
		

	local rp = Instance.new("RocketPropulsion", mouse.Target)
	mouse.Target.Anchored = false
	rp.MaxSpeed = 50
	rp.Target = player.Character.Torso
	rp:Fire()
	local distance = (mouse.Target.Position - player.Character.Torso.Position).Magnitude
	print(distance)
	mouse.Target.Touched:connect(function(hit)
		hit = hit.Parent:FindFirstChild("Humanoid") 
		if hit then
			rp:Destroy()
				
		end
		Sound:Destroy()
		debounce = false
		wait(2)
		debounce = true
	end)
		end
	end
	end)
	
	
end)
	
script.Parent.Unequipped:Connect(function()
	--what do I do here??
end)

1 answer

✓ Accepted answer

Do something like this that checks if it's equipped or not

e = false
script.Parent.Equipped:Connect(function ()
	e= true
end)

script.Parent.Unequipped:Connect(function()
	e= false
end)

--have the rest of the stuff here but have it check if e is true or not

For the cooldown

a = false
function cool()
a = true
wait(cooldown time)
a = false
end
if a == false and e == true then
--all the stuff here
cool()

4 comments

0

That works, but I need to have a cool-down time, too.

0

I need to keep this part: "debounce = false wait(2) debounce = true"

0

The equip part shouldn't interfere with the cooldown if it already worked, though. I don't think you need to change it to what I have.

0

It worked. Thanks.

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