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

Can somebody help me make a script which makes you stop when you click/run your animation?

Asked by 5 years ago

What i want to do is make it so when you right click/run animation it puts your jumppower and walkspeed to 0 so you can't move for 3 seconds

the script is a local script and is in a tool

local canUse = true

script.Parent.Equipped:Connect(function(Mouse)
    Mouse.Button2Down:Connect(function()
        if canUse then
            canUse = false
            animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Heavy1)
            animation:Play()
            wait(3)
            canUse = true
        end
    end)
end)

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

2 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

So just implement those changes into your script. They're pretty minor

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 --record previous values
            char.Humanoid.WalkSpeed = 0
            char.Humanoid.JumpPower = 0
            animation = char.Humanoid:LoadAnimation(script.Parent.Heavy1)
            animation:Play()
            wait(3)
            canUse = true
            char.Humanoid.WalkSpeed = WalkSpeed
            char.Humanoid.JumpPower = JumpPower
        end
    end)
end)

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

0
if you're looking to completely disable movement, you can disable the ControlScript Gey4Jesus69 2705 — 5y
Ad
Log in to vote
1
Answered by 5 years ago

Just before you play the animation, set the walk speed and jump power to 0.

local tool = script.Parent
local client = game:GetService("Players").LocalPlayer -- # you can name the variable player if you want
local canUse = true
local animation
local connection

tool.Equipped:Connect(function(Mouse)
    connection = Mouse.Button2Down:Connect(function()
        if canUse then
            local humanoid = client.Character.Humanoid
            canUse = false
            humanoid.WalkSpeed = 0
            humanoid.JumpPower = 0
            animation = humanoid:LoadAnimation(tool.Heavy1)
            animation:Play()
            wait(3)
            humanoid.WalkSpeed = 16
            humanoid.JumpPower = 50
            canUse = true
        end
    end)
end)

tool.Unequipped:Connect(function()
    local humanoid = client.Character.Humanoid
    humanoid.WalkSpeed = 16
    humanoid.JumpPower = 50
    animation:Stop()
    connection:Disconnect()
end)

The default WalkSpeed is 16, where the default JumpPower is 50. You can also notice the predeclared animation and connection variables. The animation variable is there so that you do not need to use a global variable. The usage of global variables is bad practice, they make your code base a mess.

The animation variable is instead available as an upvalue (external local variable) in the event listeners, and I disconnect connections since your Button2Down event listener is nested in your Equipped event listener, which means new connections are being created each time you equip the tool.

0
mine is better bc it sets it back to the previously set walkspeed and jumppower :)) Gey4Jesus69 2705 — 5y

Answer this question