✓ Accepted answer
Okay, so I had to rewrite your code as I noticed a big problem with your script. You're using LocalPlayer which only works in local scripts, but changing the leaderstats on a local script will only show for you and not everyone else.
I fixed this by making the script a server (normal) script and getting the player that equipped the tool instead of the LocalPlayer. I also added a debounce to prevent spam.
Here's the code:
local Players = game:GetService("Players")
local tool = script.Parent
local plr
local Character
local Humanoid
local Anim = Instance.new("Animation")
Anim.AnimationId = "rbxassetid://4139476411"
local PlayAnim
local debounce = false
tool.Activated:Connect(function()
if debounce == true then
return
end
debounce = true
if PlayAnim ~= nil then
PlayAnim:Play()
wait(.7)
plr.leaderstats.Strength.Value = plr.leaderstats.Strength.Value + 1
PlayAnim:Stop()
end
debounce = false
end)
tool.Equipped:Connect(function()
plr = Players:GetPlayerFromCharacter(script.Parent.Parent)
if plr ~= nil then
Character = plr.Character
Humanoid = Character:WaitForChild("Humanoid")
PlayAnim = Humanoid:LoadAnimation(Anim)
end
end)
Hope this helped! Sorry for making all this complicated. If you have any questions, just comment!
12 comments
You’re playing the animation but then immediately stopping it afterwards, so it’ll look like it won’t play at all. You could either remove line 11 or add a wait before it.
did not work
Can you post what you edited in your code? Also did you get any errors or warnings?
I did not have any errors and here is the code
I edited the post so I added a wait before line 11.
It seems to work for me. Is this a local script? If not, it won't work as LocalPlayer is only available through local scripts. Also check to make sure your animation is designed properly.
Weird... IT is a local script. It wont work ;-;
OOOOH I SEE! The animation was not good.
@Denny9876 so when i use an auto clicker it re-plays the script real fast. Is there a way to fix that?
^ You use a debounce for that. I'll make an answer to explain it. Also I found another problem which I will also explain.
Nvm, fixed and yes i used debounce ^^ thanks <3
Answer would be awesome thanks ^^