What do you want to achieve? Keep it simple and clear!
A animation that plays even after the character respawns.
What is the issue? Include screenshots / videos if possible!
The script works fine the first time, however when the character respawns the script is unable to provide animationclipservice.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
yes, none worked
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Hum = Character:WaitForChild('Humanoid')
local RS = game:GetService("ReplicatedStorage")
local Tool = script.Parent
local LSHOLDANIM = Tool:WaitForChild("LSHOLD")
local LSSwing1 = Tool:WaitForChild("LSSwing1")
local LSSwing2 = Tool:WaitForChild("LSSwing2")
local LSSwing3 = Tool:WaitForChild("LSSwing3")
local Equipped = false
local Debounce = false
-- Load anims
local Swing1 = Hum:LoadAnimation(LSSwing1)
local Swing2 = Hum:LoadAnimation(LSSwing2)
local LSHold = Hum:LoadAnimation(LSHOLDANIM)
local Swing3 = Hum:LoadAnimation(LSSwing3)
local animations = {Swing1,Swing2,Swing3}
Player.CharacterAdded:Connect(function(Char)
Character = Char
Hum = Char:WaitForChild("Humanoid")
end)
-- Tool equipped
Tool.Equipped:Connect(function()
Equipped = true
LSHold:Play()
end)
Tool.Unequipped:Connect(function()
Equipped = false
LSHold:Stop()
end)
Tool.Activated:Connect(function()
if Debounce == false and Equipped then
print("r")
RS.swordevent:FireServer()
Debounce = true
animations[math.random(1,3)]:Play()
wait(3)
Debounce = false
end
end)
repeat wait() until Player.Character
local Character = Player.Character or Player.CharacterAdded:Wait()
This should work.
It know it seems like the exact same thing but for some reason LocalScripts within the StarterPack act very strange when trying to deal with the Character, and this fixes it for some reason.
You can remove the repeat wait() loop, it does basically the same thing as CharacterAdded:Wait(), but CharacterAdded is faster and generally a standard for waiting for the character to load.
I know it does but for some reason it fixes this issue, it’s strange. That’s why instead of loading any of my tools from StarterPack I just load them from the server with a CharacterAdded function, so none of these strange errors occur.