well, I need help again… I think i screwed up right now.
local function makeSurrender()
local npc = workspace.NPC
local makeSurrender = npc:FindFirstChild("SurrenderAnimation")
if makeSurrender then
makeSurrender:Play()
else
print("SurrenderAnimation not found!")
end
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.HealthChanged:Connect(function(Health)
if Health < 90 then
makeSurrender()
end
end)
end)
end)
local npc = workspace.NPC
local makeSurrender = npc:FindFirstChild("SurrenderAnimation"):LoadAnimation()
if makeSurrender then
makeSurrender:Play()
else
print("SurrenderAnimation not found!")
end
It won’t work if you didn’t publish the animation, or you don’t own it.
local function makeSurrender()
local npc = workspace.NPC
local makeSurrender = npc:FindFirstChild("SurrenderAnimation")
local humanoid = npc:FindFirstChild("Humanoid")
if makeSurrender and humanoid then
local surrenderAnim = humanoid.Animator:LoadAnimation(makeSurrender)
surrenderAnim:Play()
else
print("SurrenderAnimation not found!")
end
end
That means that the function is not being called, which means that you messed up somewhere here:
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.HealthChanged:Connect(function(Health)
if Health < 90 then
makeSurrender()
end
end)
end)
end)
Did you change the humanoid.HealthChanged:Connect() to what @Den_vers stated?: :GetPropertyChangedSignal("Health"):Connect()
local function makeSurrender()
local npc = workspace.NPC
local makeSurrender = npc:FindFirstChild("SurrenderAnimation")
local humanoid = npc:FindFirstChild("Humanoid")
if makeSurrender and humanoid then
local surrenderAnim = humanoid.Animator:LoadAnimation(makeSurrender)
surrenderAnim:Play()
else
print("SurrenderAnimation not found!")
end
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid:GetPropertyChangedSignal("Health"):Connect(function()
local Health = humanoid.Health
if Health < 90 then
makeSurrender()
end
end)
end)
end)
The issue I am seeing here, is first that you are not loading the animation properly. You must load it somewhat like this.
local function makeSurrender()
local npc = workspace:FindFirstChild("NPC")
local makeSurrenderAnim = -- [[Path to your animation instance for now it's nil]]
nil
if makeSurrenderAnim ~= nil then
local makeSurrenderAnimTrack = npc:FindFirstChildOfClass("Humanoid").Animator:LoadAnimation(makeSurrenderAnim)
makeSurrenderAnimTrack:Play()
end
end
Also you are checking the player health and then making the NPC surrender which doesn’t make sense, so if you’re trying to make the NPC surrender at a certain health amount you need to connect the event to the NPC’s humanoid, not the player’s. Unless the player is getting hurt the NPC will not surrender in this instance.