What should be issue in this script?

local Humanoid = script.Parent.Humanoid
deb = false
function PwntX_X() 
	script.Parent.HumanoidRootPart.Touched:connect(function(part)
		if game.Players:FindFirstChild(part.Parent.Name) then
			if deb == false then
				deb = true
				local plr = game.ServerStorage.PlayerMoney:FindFirstChild(part.Parent.Name)
				plr.Value = plr.Value + 500
				wait(5)
				deb = false
			end
		end
	end)
script:remove() 
end 
Humanoid.Died:connect(PwntX_X) 

It does not give me any error btw

1 Like

Can you explain what you’re trying to achieve with this script?

When a player kills the zombie, he should get money

You miss spelled Connect…
(chars)

That’s not the cause connect is now deprecated, but still works (usually) if you look at a lot of Roblox source like some scripts for chat you will see lowercase connect a lot, though it is a better idea to useConnect

1 Like

Okay, this whole script is messed up. You add a touch event to the HRP when the zombie dies. What you should instead be doing is look for a creator tag in the Humanoid that you have to create and put there in your weapon scripts. To learn to do this a quick google or YouTube search for How to make cash for kill on Roblox will get you results and what you need

I have tried everything, but I want to change in server storage, but I can not manage how to do that. Every time I try a new script, new errors are pops up!

I try this script now

local Humanoid = script.Parent.Humanoid
function Dead()
	local tag = Humanoid:FindFirstChild("creator")
	if tag ~= nil then
		if tag.Value ~= nil then
			local leaderstats = tag.Value:FindFirstChild("leaderstats")
			if leaderstats ~= nil then
				local plr = game.ServerStorage.PlayerMoney:FindFirstChild(tag.Parent.Name)
				plr.Value = plr.Value + 500
				wait(5)
				script:Remove()
			end
		end
	end
end
Humanoid.Died:Connect(Dead)

And I am getting this error:

Workspace.Zombie Spawn.Zombie.Script:9: attempt to index nil with ‘Value’

Unfortunately, it did not work, but thank you for your time! I tried everything but sadly nothing works! :frowning:

try this, Normal Script On Zombie:

local Hum = script.Parent.Humanoid

function Dead()
	local tag = Hum:WaitForChild("creator")
	if tag ~= nil then
		if tag.Value ~= nil then
			local l = tag.Value:WaitForChild("leaderstats")
			if l ~= nil then
				l.Cash.Value = l.Cash.Value + 500
				wait(0.1)
			end
		end
	end
end

Hum.Died:Connect(Dead)

Script On ServerScriptService:

game.Players.PlayerAdded:Connect(function(plr)
	local l = Instance.new("Folder", plr)
	l.Name ="leaderstats"
	local C = Instance.new("NumberValue", l)
	C.Name = "Cash"
	C.Value = 0
end)

Your Weapon Must have a script that adds the tag on the humanoid that the value is the player that used the weapon

Note:
if your Value is not on player.leaderstats, then replace l.Cash.Value to where the players Value is

Mark this comment as solution if it worked

or Use How to make a Kill NPC For Cash Script ROBLOX Studio Tutorial - YouTube for everything that supports it

:remove() is deprecated. :connect() is deprecated.

It looks like there’s a few problems.

Anyways, you cannot detect if a player’s character’s humanoid died from a server script.

use a sword created by roblox
it should work

btw im using :Connect() not :connect()

it worked for me

i meant create a local script to addd a value if the player/npc is dead

oh eya btw

game.ServerStorage.PlayerMoney:FindFirstChild(part.Parent.Name) -- on your old script

should be replaced by

game.ServerStorage.PlayerMoney:FindFirstChild(tag.Value)

Have you created a Cash Value already? If you haven’t, do the following:

Insert a Server Script in ServerScriptService, then use the following code below:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder") -- Creates a folder
	leaderstats.Name = "leaderstats" -- Renames folder to 'leaderstats'
	
	local CashValue = Instance.new("IntValue") -- Creates an 'IntValue'
	CashValue.Name = "Cash" -- Renames IntValue to 'Cash'
	CashValue.Value = 0 -- Amount of cash players will have when they first join
	
	CashValue.Parent = leaderstats -- Parents the IntValue to the Folder
	leaderstats.Parent = player -- Parents the folder to the player
end)

Now for the script in the NPC, use the following code below:

local Humanoid = script.Parent:WaitForChild("Humanoid") -- Gets the humanoid

function Dead()
	local tag = Humanoid:FindFirstChild("creator") -- gets the creator tag
	if tag ~= nil then -- checks if the tag exists
		if tag.Value ~= nil then -- checks if the player exists
			local leaderstats = tag.Value:FindFirstChild("leaderstats") -- gets the leaderstats folder
			if leaderstats ~= nil then -- makes sure leaderstats exist
				leaderstats.Cash.Value += 500 -- rewards 500 cash to the player
				task.wait(5) -- waits 5 seconds
				script:Destroy() -- script gets deleted
			end
		end
	end
end

Humanoid.Died:Connect(Dead)

This should fix the current issues you are facing.