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

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

Asked by 7 years ago

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

Log in to vote
1
Answered by
Viking359 161
7 years ago
Edited 7 years ago

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()
0
That works, but I need to have a cool-down time, too. chia_pet 24 — 7y
0
I need to keep this part: "debounce = false wait(2) debounce = true" chia_pet 24 — 7y
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. Viking359 161 — 7y
0
It worked. Thanks. chia_pet 24 — 7y
Ad

Answer this question