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:
01 | function 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(Vector 3. new( 0 , 50 , 0 )) |
13 | end |
14 | end |
15 | Figure:Remove() |
16 | return |
17 | end ) |
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