I am an encountering an error with my script that the script doesn’t work entirely and instead gives me the following error:
This is the script.
local onPlayerLoaded = function(player)
local onCharacterLoaded = function(Char)
local humanoid = Char:WaitForChild("Humanoid")
local hrp = Char:WaitForChild("HumanoidRootPart")
local anim = humanoid:LoadAnimation(incap)
humanoid.HealthChanged:Connect(function()
print("Health changed");
if humanoid.Health <= 50 then
local ClonedGui = script.Gone:Clone()
ClonedGui.Parent = player.PlayerGui
anim:Play()
hrp.Anchored = true
end;
end);
end;
player.CharacterAdded:Connect(onCharacterLoaded);
if(player.Character) then onCharacterLoaded(player.Character) end;
end;
game.Players.PlayerAdded:Connect(onPlayerLoaded);
for _, p in pairs(game:GetService("Players"):GetPlayers()) do
onPlayerLoaded(p);
end;