I made a script that is supposed to give a player a rare item when the NPC is killed. It works in studio when I test it, but when I fire up a server to test it, it doesn't work. Anyone know why?
script in NPC model:
local Humanoid = script.Parent.Human
local items = game.ReplicatedStorage.Swords
local plr = game.Players.LocalPlayer
function PwntX_X()
local tag = Instance.new('ObjectValue',Humanoid)
tag.Name = 'creator'
tag.Value = plr
if tag ~= nil then
if tag.Value ~= nil then
local droprate = math.random(1,1)
if droprate == 1 then
print("Bandit LongSword")
local tb = items["Bandit LongSword"]:Clone()
local tb2 = items["Bandit LongSword"]:Clone()
tb.Parent = plr.Backpack
tb2.Parent = plr.StarterGear
end
wait(3)
tag:Destroy()
local Leaderstats = tag.Value:findFirstChild("leaderstats")
if Leaderstats ~= nil then
Leaderstats.Gold.Value = Leaderstats.Gold.Value + 5
wait(0.1)
script:remove()
end
end
end
end
Humanoid.Died:connect(PwntX_X)

4 comments
line 15 should be StarterGear not StarterPack. Also we need more context as to what "creator" is. Print debug it
I'm not sure what the "creator" value is, I can't find it anywhere, but I do know that its supposed to tag the player, I'll rewrite that and see what happens.
I rewrote it but I still have the same problem.
The creator tag is commonly used in leaderboard/weapon scripts to detect the killer of a character.