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

What am i doing wrong in this animation script? *REPOSTED AND UNSOLVED*

Asked by
Sorukan 240 Moderation Voter
6 years ago
Edited 6 years ago

I'm trying to make a script for a tool where pressing the X button would only play the animation if my tool was equipped. Problem is, when i unequipped the tool i can continue to press x again and the animation would still play.

01-//Services
02local UIS = game:GetService('UserInputService')
03 
04--//Variables
05local tool = script.Parent
06local player = game.Players.LocalPlayer
07local char = player.Character
08 
09--//Use this since it's a local script inside a tool
10player.CharacterAdded:Connect(function(character)
11char = character
12local hum = char:WaitForChild('Humanoid')
13 
14--//Animation
15local spinSlash = hum:LoadAnimation(tool.Animation) -- i have the animation inside the tool.
View all 36 lines...

Again, i only want the x button to play the animation when the tool is equipped.

0
first of all you should never repost your questions especially if they were moderated DeceptiveCaster 3761 — 6y
0
Last time i checked it wasn't moderated, plus what's wrong with reposting a question that i've been struggling with for a whole week already? Sorukan 240 — 6y
0
^ it will be classed as a duplicate and moderated again. User#5423 17 — 6y
0
Great, so my question will never get an answer...thanks scripting "helpers" Sorukan 240 — 6y
0
And the last time that i checked the community guidelines, there are no rules saying you can't repost or make duplicates, it's not like i'm spamming the post, infact i've reposted this about 4 times already and each time i did it i waited atleast a day or 2 before reposting it again only to get no answers. Sorukan 240 — 6y

1 answer

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

Try this:

01--//Equipped
02tool.Equipped:Connect(function()
03 
04--//Input
05local debounce = false
06local playSlash = UIS.InputBegan:Connect(function(input)
07    if input.KeyCode == Enum.KeyCode.X and not debounce then
08        debounce = true
09        spinSlash:Play()
10        wait(2)
11        debounce = false
12    end
13    end)
14end)
15 
View all 21 lines...

It makes the 'pressing X' event a variable so that it can be disconnected once you unequip the item.

To answer your question, you were doing nothing wrong, it was just that you need to do a little bit extra to get the :Connect() to stop.

1
Thank u so much! Sorukan 240 — 6y
Ad

Answer this question