Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does this give money on kill script not work on my zombie in workspace?

local Humanoid = script.Parent.Humanoid
function PwntX_X()
	local tag = Humanoid:findFirstChild("creator")
	if tag ~= nil then
		if tag.Value ~= nil then
			local Leaderstats = tag.Value:findFirstChild("leaderstats")
			if Leaderstats ~= nil then
				Leaderstats.Coins.Value = Leaderstats.Coins.Value + 10 --how much you get for killing the npc
				wait(0.1)
				script:remove()
			end
		end
	end
end
Humanoid.Died:connect(PwntX_X)

theres no error in output (atleast of what i saw). My leaderstats name is the same, so is coins.

1 answer

If the humanoid has "creator" value in it - delete it. If the noob icon inside of the enemy is named Humanoid - this should work. Put this as a script inside of the enemy model.

local type = "Coins"

bot = script.Parent
human = bot.Humanoid

cash = 10



function onDied()
	local killer = human:findFirstChild("creator")
	if killer~=nil then
		local money = killer.Value.leaderstats:findFirstChild(type)
		if money~= nil then
			money.Value = money.Value + cash
		end
	end
end

script.Parent.Humanoid.Died:connect(onDied)

This discussion is preserved as it was. New answers, comments, and votes are closed.