local _M = require(script.Parent.MobConfig) local Mob = script.Parent local Enemy = Mob.Enemy Enemy.Died:Connect(function() if (not Enemy:FindFirstChild("creator")) then return end local tag = Enemy.creator local player = game.Players:GetPlayerFromCharacter(tag.Value) local Stats = player:WaitForChild("leaderstats") local XP = Stats:WaitForChild("XP") local Gold = Stats:WaitForChild("Gold") XP.Value = XP.Value + _M.XPAward Gold.Value = Gold.Value + _M.GoldAward end)
the error in output:
Workspace.Bald Gang Member(lvl 5).RewardScript:8: attempt to index local 'player' (a nil value)
This answer is REALLY simple:
a) tag.Value is not a Character. The parameter of GetPlayerFromCharacter() must be a Character.
b) Local variables, when used outside of the scope they're defined in, have no value.
If I'm not mistaken, you're using the method that Linked swords use to change values right? If that's the case, then you can't call GetPlayerFromCharacter() on an Object Value because an Object Value is not the character, in that instance it only stores the value of the player. Your error is caused because if the GetPlayerFromCharacter() function can't find a player, then it returns nil instead. A better way to get the player from the Object Value is just to do this: local player = tag.Value
then change the stats from there.