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 5 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:

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)
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 — 5y
0
Ill see if this works CaptainD_veloper 290 — 5y

1 answer

Log in to vote
0
Answered by 5 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 — 5y
Ad

Answer this question