im trying to give the player XP when they kill an enemy, ive tagged the enemy the player hits with an Object tag with the value being the players name and giving them xp from a script in the enemy they are attacking, the problem is that the script only gets up to "print("NPC Died")
local NPC = script.Parent
local Humanoid = NPC:WaitForChild("Humanoid")
local Players = game:GetService("Players")
local respawnTime = 5
local plrAttacked = {}
local npc_Clone = NPC:Clone()
Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
if Humanoid.Health <= 0 then
print("NPC Died")
for _, plrs in pairs(Humanoid:GetChildren()) do
if plrs:IsA("ObjectValue") then
print("is object")
local plrFound = Players:FindFirstChild(plrs).Value
print("Got Value")
if plrFound then
local PlrStats = plrFound:FindFirstChild("Attributes")
local PlrCurrency = plrFound:FindFirstChild("Leaderstats")
if PlrStats then
local Exp = PlrStats:FindFirstChild("EXP")
local Shards = PlrCurrency:FindFirstChild("Shards")
local Gold = PlrCurrency:FindFirstChild("Gold")
if Exp and Shards and Gold then
Exp.Value += 25
Shards.Value += 1
Gold.Value += 20
end
end
end
end
end
wait(respawnTime)
npc_Clone.Parent = workspace
NPC:Destroy()
end
end)

2 comments
You are trying to get a player from a objectvalue instance? Don't you mean getting only the ObjectValue.Value?
the objects value is the players name