So I’m trying to print the lastAttacker, and winAward from the model, and for some reason its printing nil… Any suggestions?
local CS = game:GetService("CollectionService")
local Enemies = CS:GetTagged("Enemy")
local ragdoll = require(game.ReplicatedStorage.Modules.Ragdoll)
local function EnemyDeath(Enemy : Model)
print("Enemy died")
local lastAttacker = Enemy:GetAttribute("LastAttacker")
print(lastAttacker)
local winAward = Enemy:GetAttribute("WinAward")
print(winAward)
Enemy.Humanoid.Died:Connect(function()
if lastAttacker and lastAttacker:IsA("Player") then
local playerName = lastAttacker.Name
print("Last Attacker's Name:", playerName)
end
end)
end
for i,v in pairs(Enemies) do
if v:FindFirstChild("Humanoid") ~= nil then
print("Name: "..v:GetAttribute("Name"))
print("Health: "..v:GetAttribute("Health"))
local health = v:GetAttribute("Health")
local name = v:GetAttribute("Name")
v.Humanoid.MaxHealth = health
v.Humanoid.Health = health
v.Humanoid.BreakJointsOnDeath = false
v.Humanoid.Died:Connect(function()
--Ragdoll the NPC/Enemy
if v:GetAttribute("isBoss") == true then
--Boss logic
EnemyDeath(v)
return
else
--Maybe use a function here?
EnemyDeath(v)
end
end)
end
end