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 6 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

01local canUse = true
02 
03script.Parent.Equipped:Connect(function(Mouse)
04    Mouse.Button2Down:Connect(function()
05        if canUse then
06            canUse = false
07            animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Heavy1)
08            animation:Play()
09            wait(3)
10            canUse = true
11        end
12    end)
13end)
14 
15script.Parent.Unequipped:Connect(function()
16        animation:Stop()
17end)

2 answers

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

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

01local canUse = true
02local player = game.Players.LocalPlayer
03local char = player.Character or player.CharacterAdded:Wait()
04 
05script.Parent.Equipped:Connect(function(Mouse)
06    Mouse.Button2Down:Connect(function()
07        if canUse then
08            canUse = false
09            local Walkspeed = char.Humanoid.WalkSpeed
10            local JumpPower = char.Humanoid.JumpPower --record previous values
11            char.Humanoid.WalkSpeed = 0
12            char.Humanoid.JumpPower = 0
13            animation = char.Humanoid:LoadAnimation(script.Parent.Heavy1)
14            animation:Play()
15            wait(3)
View all 25 lines...
0
if you're looking to completely disable movement, you can disable the ControlScript Gey4Jesus69 2705 — 6y
Ad
Log in to vote
1
Answered by 6 years ago

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

01local tool = script.Parent
02local client = game:GetService("Players").LocalPlayer -- # you can name the variable player if you want
03local canUse = true
04local animation
05local connection
06 
07tool.Equipped:Connect(function(Mouse)
08    connection = Mouse.Button2Down:Connect(function()
09        if canUse then
10            local humanoid = client.Character.Humanoid
11            canUse = false
12            humanoid.WalkSpeed = 0
13            humanoid.JumpPower = 0
14            animation = humanoid:LoadAnimation(tool.Heavy1)
15            animation:Play()
View all 30 lines...

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 — 6y

Answer this question