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
01 | local canUse = true |
02 |
03 | script.Parent.Equipped:Connect( function (Mouse) |
04 | Mouse.Button 2 Down:Connect( function () |
05 | if canUse then |
06 | canUse = false |
07 | animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Heavy 1 ) |
08 | animation:Play() |
09 | wait( 3 ) |
10 | canUse = true |
11 | end |
12 | end ) |
13 | end ) |
14 |
15 | script.Parent.Unequipped:Connect( function () |
16 | animation:Stop() |
17 | end ) |
So just implement those changes into your script. They're pretty minor
01 | local canUse = true |
02 | local player = game.Players.LocalPlayer |
03 | local char = player.Character or player.CharacterAdded:Wait() |
04 |
05 | script.Parent.Equipped:Connect( function (Mouse) |
06 | Mouse.Button 2 Down: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.Heavy 1 ) |
14 | animation:Play() |
15 | wait( 3 ) |
Just before you play the animation, set the walk speed and jump power to 0.
01 | local tool = script.Parent |
02 | local client = game:GetService( "Players" ).LocalPlayer -- # you can name the variable player if you want |
03 | local canUse = true |
04 | local animation |
05 | local connection |
06 |
07 | tool.Equipped:Connect( function (Mouse) |
08 | connection = Mouse.Button 2 Down: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.Heavy 1 ) |
15 | animation:Play() |
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.