When The Humanoid Has Died I want To Reward the Player with 25 Exp.
This Code Is Not Rewarding The Player After The Humanoid Has Died.
I am not getting any errors in the output
I do Have a folder named PlayerStats and an Exp Value spelled Exactly The Same so I don’t think anything is wrong with my spelling.
local NPC = script.Parent
local Humanoid = NPC:WaitForChild("Humanoid")
local RespawnTime = 1
local expGiven = 25
local PlayerAttacked = {}
local npc_Clone = NPC:Clone()
Humanoid.Died:Connect(function()
-- This will be where we manage who attacked the NPC
for _, players in pairs(Humanoid:GetChildren()) do
if players:IsA("StringValue") then
local PlayerFound = players:FindFirstChild(players.Name)
if PlayerFound then
local PlayerStats = PlayerFound:FindFirstChild("PlayerStats")
if PlayerStats then
local Exp = PlayerStats:FindFirstChild("Exp")
if Exp then
Exp.Value += expGiven
end
end
end
end
end
wait(RespawnTime)
npc_Clone.Parent = workspace
NPC:Destroy()
end)