I encountered an error when I clicked the mouse to play the animation immediately after spawning in my script. The script is currently parented to “ScreenGui,” and I have disabled the “ResetOnSpawn” option.
.
This is my script:
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local char = player.Character or player.CharacterAdded:Wait()
local Humanoid = char:WaitForChild("Humanoid")
local HumanoidRootPart = char:WaitForChild("HumanoidRootPart")
local Animation = script:WaitForChild("Animation")
local canPlayAnimation = true
mouse.Button1Down:Connect(function()
if not canPlayAnimation then return end
local animation = Humanoid:LoadAnimation(Animation)
animation:Play()
end)
--Player RespawnTime == 1
Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
if Humanoid.Health <= 0 then
canPlayAnimation = false
wait(3)
char = player.Character or player.CharacterAdded:Wait()
print("Character Loaded")
Humanoid = char:WaitForChild("Humanoid")
print("Humanoid Loaded")
HumanoidRootPart = char:WaitForChild("HumanoidRootPart")
print("HumanoidRootPart Loaded")
canPlayAnimation = true
end
end)
The ERROR:
Stack Begin
Script ‘Players.davidrhee1234.PlayerGui.ScreenGui.LocalScript’, Line 17
Stack End