NPC not giving laser gun when killed

Hi, i have a model name Zombie, when i kill her i gain 25 money (it’s good) but i don’t loot the Laser Gun :confused: someone see any error in the script ?

local Humanoid = script.Parent.Zombie

function PwntX_X()

local tag = Humanoid:findFirstChild(“creator”)

if tag ~= nil then

if tag.Value ~= nil then

local Leaderstats = tag.Value:findFirstChild(“status”)

local gear = game.ReplicatedStorage.Items:WaitForChild(‘LaserGun’)

if Leaderstats ~= nil then

Leaderstats.Money.Value = Leaderstats.Money.Value + 25 --Change Money to the stat that is increased.

gear:Clone().Parent = game.Players.PlayerName.Backpack

– end

end

wait(0.1)

script:Destroy()

end

end

end

Humanoid.Died:connect(PwntX_X)

1 Like

What is PlayerName supposed to be? It looks like you want to get a certain player, but what player are you trying to get?

Me ^^ Game.Players.PlayerName.Backpack it’s not the player who kill the zombie ?

Try This:

local Humanoid = script.Parent.Zombie

function PwntX_X()

local tag = Humanoid:findFirstChild(“creator”)

if tag ~= nil then

if tag.Value ~= nil then

local Leaderstats = tag.Value:FindFirstChild(“status”)

local gear = game.ReplicatedStorage.Items:WaitForChild(‘LaserGun’)

if Leaderstats ~= nil then

Leaderstats.Money.Value = Leaderstats.Money.Value + 25 --Change Money to the stat that is increased.

gear:Clone().Parent = game.Players.LocalPlayer.Backpack  -- **I fixed this so it issues it to the player's backpack, not their name.**

– end

end

wait(0.1)

script:Destroy()

end

end

end

You’re trying to get a player who is named “PlayerName”. That probably won’t be a real player. You have to replace PlayerName with the player that you want to give the tool to.

Not work :confused: LaserGun don’t go in my Backpack

This will not work, because the script seems to be in the Zombie model, and LocalScripts won’t run there.

^Your right, I wasn’t thinking about it being Local.