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

How do I give cash to the person who kills an npc?

If I have an npc, and when it dies, I want it to give cash, what would I add to my script? Here is my script:

function onDied()
		pose = "Dead"
		Delay(5, function()
			if script.Parent.Respawn.Value == true then
				CheckSpawns(Workspace)
				local Spawn = SpawnModel:GetChildren()
				Clone.Parent = game.Workspace
				if #Spawn > 0 then
					Spawn = Spawn[math.random(1, #Spawn)].Value
					Clone:MoveTo(Spawn)
				else
					Clone:MoveTo(Vector3.new(0, 50, 0))
				end
			end
			Figure:Remove()
			return
		end)

2 comments

0

You'll need to figure out which player killed it, so if its a gun, have a function called when a remote even is fired from the player shooting. After shooting, have the server script check if the NPC is there and then damage the NPC. If the NPC's health is 0 then Cash = Cash + Amount. 

0

Ill see if this works

1 answer

When the NPC Dies find the player which you have first get the weapons parent when npc died(character) then get the player from character(game.Players:GetPlayerFromCharacter(character)) then add cash to it but make sure you have leaderstats so they can get cash

1 comment

0

Okay, this is helpful, but. You have explained it poorly. Not trying to sound like a douche, but you are not using format and for some reason when I read your answer, I felt as if you were rushing it. I've seen your other answers though, they're pretty good. But, probably fix this answer. Good job nonetheless.

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