Hello everyone, I’m posting this forum on purpose ask for help to solve a problems I am struggling with
Problem:
The issue is the connections line “Humanoid(NPC).Changed:Connect” it behaviour is weird, it’s alway work with player and with rig(npc) it’s never work on some specific damage source but few are work ( All damage source use :TakeDamage )
What did i do:
apparently i meet this problem for the 2nd time and each time i use a different script:
- i was make a variety of connection in script 1 and the result is still not work
Script 1 (Spawn partical Emiter)
game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(spawnPartAtDeathPosition) end) for _, npc in pairs(workspace:GetDescendants()) do if npc:FindFirstChild("Humanoid") then spawnPartAtDeathPosition(npc) end end workspace.DescendantAdded:Connect(function(descendant) if descendant:IsA("Model") and descendant:FindFirstChild("Humanoid") then spawnPartAtDeathPosition(descendant) end end)
Script 2 (spawn gui)
local function monitorHumanoid(humanoid)
local crit = nil
local lastHealth = humanoid.Health – Store initial health value
– Stuck at here
humanoid.HealthChanged:Connect(function(newHealth)
local healthChange = newHealth - lastHealth – Calculate the change in healthif Collector:HasTag(humanoid, "GetCrited") then crit = true LifeTime = 2 else crit = false LifeTime = 0.5 end local character = humanoid.Parent local position = nil if character and character:FindFirstChild("HumanoidRootPart") then position = character.HumanoidRootPart.Position -- Get the position else warn("HumanoidRootPart not found for " .. humanoid.Parent.Name) end SpawnGui(position, healthChange, crit) lastHealth = newHealth end)
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild(“Humanoid”)
monitorHumanoid(humanoid)
end)
end)– this loop work
for _, npc in ipairs(workspace:GetDescendants()) do
if npc:IsA(“Model”) and npc:FindFirstChild(“Humanoid”) then
print(“found npc”)
monitorHumanoid(npc:FindFirstChild(“Humanoid”))
end
endworkspace.DescendantAdded:Connect(function(descendant)
if descendant:IsA(“Model”) and descendant:FindFirstChild(“Humanoid”) then
monitorHumanoid(descendant:FindFirstChild(“Humanoid”))
end
end)
both of them doesn’t warn anything
Pls help me:(