My script is supposed to give XP to a person that kills an NPC, however i've run into problems along the way.
(script i am having trouble with)
local humanoid = script.Parent.Humanoid humanoid.Died:Connect(function() game.ServerStorage:WaitForChild("Events").GiveXp:Fire(100, humanoid.creator.Value) end)
(damage script)
script.Parent.Touched:Connect(function(hit) local DmgValues = {script.Dmg.Value, script.DmgCritical.Value, script.Dmg2.Value, script.Dmg3.Value, script.DmgCritical2.Value} local char = hit.Parent local hum = char:FindFirstChild("Humanoid") local chance = math.random(1, #DmgValues) if hum and char.Name ~= script.Parent.Parent.Name then hum.Health = hum.Health - DmgValues[chance] script.Disabled = true wait(0.5) script.Disabled = false -- THIS PART ONLY BELOW local player = game.Players.LocalPlayer if hit.Parent.Humanoid.Health <= 0 then local creator = Instance.new("ObjectValue") creator.Name = "creator" creator.Parent = hit.Parent.Humanoid creator.Value = player end end end)
I always run into an issue here, where in the output it says, "creator is not a valid member of Humanoid"
although the explorer shows that the value is indeed inside the humanoid.
How do i make it so that the system will know that the "creator" value is there?
It's because you are making the value in a localscript. Now, I am presuming you are using a localscript because it can get the player easily, but this means that no-one else will see anything the player does except for the player. The way to fix this is to turn it into a regular script and get the player by using game.Players:GetPlayerFromCharacter().
script.Parent.Touched:Connect(function(hit) local DmgValues = {script.Dmg.Value, script.DmgCritical.Value, script.Dmg2.Value, script.Dmg3.Value, script.DmgCritical2.Value} local char = hit.Parent local hum = char:FindFirstChild("Humanoid") local chance = math.random(1, #DmgValues) if hum and char.Name ~= script.Parent.Parent.Name then hum.Health = hum.Health - DmgValues[chance] script.Disabled = true wait(0.5) script.Disabled = false local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent) if hit.Parent.Humanoid.Health <= 0 then local creator = Instance.new("ObjectValue") creator.Name = "creator" creator.Parent = hit.Parent.Humanoid creator.Value = player end end end)