I have made a tool with a localscript and an animation in it, that when the tool is activated it should fire a remote event, increase their strength by one and play an animation.
Tool localscript:
local anim = script.Animation local char = game.Player.LocalPlayer.Character:Wait() script.Parent.Activated:Connect(function() local humanoid = char:WaitForChild("Humanoid") local trackanim = humanoid:LoadAnimation(anim) trackanim:Play() workspace.Event.StrengthEvent:FireServer() script.Parent.Enabled = true wait(1) script.Parent.Enabled = false end)
Event (Script in workspace in which is StrengthEvent):
script.StrengthEvent.OnServerEvent:Connect(function(player) player.leaderstats.Strength.Value = player.leaderstats.Strength.Value + 1 end)
The value will not increase and the animation will not play. And yes the animation priority is set to action Please help (if there is an error I'm still a beginner please help me point it out.)
Make sure the animation's priority is set to action.
Two problems. First game.Player.LocalPlayer.Character:Wait()
is not a proper usage. Second animation loading should be done only once, preferably outside of your function.
local anim = script.Animation local char = game.Player.LocalPlayer.Character or game.Player.LocalPlayer.CharacterAdded:Wait() local humanoid = char:WaitForChild("Humanoid") humanoid:WaitForChild("Animator") -- paranoid precaution I like to use - without it sometimes animation will not replicate properly to other players local trackanim = humanoid:LoadAnimation(anim) local debounce = false script.Parent.Activated:Connect(function() if debounce then return end debounce = true trackanim:Play() workspace.Event.StrengthEvent:FireServer() --dont use these, use debounce --[[script.Parent.Enabled = true wait(1) script.Parent.Enabled = false--]] wait(1) debounce = false end)
Hope this helps!
EDIT: I noticed your event is in the workspace. I do not know if that would work, all remote events should be in the Replicated Storage!
EDIT 2: Fix for RemoteEvent
Put your Event
folder in ReplicatedStorage
Server Script:
local StrengthEvent = game.ReplicatedStorage.Event.StrengthEvent StrengthEvent.OnServerEvent:Connect(function(player) player.leaderstats.Strength.Value = player.leaderstats.Strength.Value + 1 end)
Local Script
local anim = script.Animation local char = game.Player.LocalPlayer.Character or game.Player.LocalPlayer.CharacterAdded:Wait() local humanoid = char:WaitForChild("Humanoid") humanoid:WaitForChild("Animator") -- paranoid precaution I like to use - without it sometimes animation will not replicate properly to other players local trackanim = humanoid:LoadAnimation(anim) local eventFolder = game.ReplicatedStorage:WaitForChild("Event") local StrengthEvent = eventFolder:WaitForChild("StrengthEvent") local debounce = false script.Parent.Activated:Connect(function() if debounce then return end debounce = true trackanim:Play() StrengthEvent:FireServer() --dont use these, use debounce --[[script.Parent.Enabled = true wait(1) script.Parent.Enabled = false--]] wait(1) debounce = false end)