Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Any way to make it so scripts won't overlap and cancel each other out?

Asked by 2 months ago

I have a script that when you click it plays an animation, i'm wondering if there's any way to stop other specific scripts from playing when this one is going on because when this script is playing i can just play another animation i have that is in my game and it cancels out the animation and it allows you to move (the script makes it so you can't move while animation is playing)

these are the 2 scripts

local z = 16 --WalkSpeed
local x = 50 --JumpPower
local canUse = true
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

script.Parent.Equipped:Connect(function(Mouse)
    Mouse.Button2Down:Connect(function()
        if canUse then
            canUse = false
            local Walkspeed = char.Humanoid.WalkSpeed
            local JumpPower = char.Humanoid.JumpPower
            char.Humanoid.WalkSpeed = 0
            char.Humanoid.JumpPower = 0
            animation = char.Humanoid:LoadAnimation(script.Parent.Heavy1)
            animation:Play()
            wait(3)
            canUse = true
            char.Humanoid.WalkSpeed = z
            char.Humanoid.JumpPower = x
        end
    end)
end)

script.Parent.Unequipped:Connect(function()
        animation:Stop()
end)
local z = 16 --WalkSpeed
local x = 50 --JumpPower
local canUse = true
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

script.Parent.Equipped:Connect(function(Mouse)
    Mouse.Button1Down:Connect(function()
        if canUse then
            canUse = false
            local Walkspeed = char.Humanoid.WalkSpeed
            local JumpPower = char.Humanoid.JumpPower
            char.Humanoid.WalkSpeed = 0
            char.Humanoid.JumpPower = 0
            animation = char.Humanoid:LoadAnimation(script.Parent.Light1)
            animation:Play()
            wait(2)
            canUse = true
            char.Humanoid.WalkSpeed = z
            char.Humanoid.JumpPower = x
        end
    end)
end)

script.Parent.Unequipped:Connect(function()
        animation:Stop()
end)

these are both essentially the same scripts but they require different buttons to activate them

0
you're using hacky method, probably why they are cancelling each other out. try using the same button along with a debounce darkhenry 93 — 2mo
0
yeah and can you tell me why you are doing this in the first place DominusInfinitus 240 — 2mo
0
i'm just trying to make a game and can you make these comments answers please so i can accept Averted_Vision 23 — 2mo
1
you can use this to see if there's already animations playing https://developer.roblox.com/api-reference/function/Humanoid/GetPlayingAnimationTracks gioni01 2015 — 2mo

Answer this question