Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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:

01function onDied()
02        pose = "Dead"
03        Delay(5, function()
04            if script.Parent.Respawn.Value == true then
05                CheckSpawns(Workspace)
06                local Spawn = SpawnModel:GetChildren()
07                Clone.Parent = game.Workspace
08                if #Spawn > 0 then
09                    Spawn = Spawn[math.random(1, #Spawn)].Value
10                    Clone:MoveTo(Spawn)
11                else
12                    Clone:MoveTo(Vector3.new(0, 50, 0))
13                end
14            end
15            Figure:Remove()
16            return
17        end)
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.  Stephenthefox 94 — 6y
0
Ill see if this works CaptainD_veloper 290 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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

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. TheOnlySmarts 233 — 6y
Ad

Answer this question