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 get points after killing an NPC?

I dont know how to do the script this is my leaderboard (it works)

rint("Cash Leaderboard Loaded")

function onPlayerEntered(newPlayer)
	 
	    local stats = Instance.new("IntValue")
	    stats.Name = "leaderstats"
	 
	    local cash = Instance.new("IntValue")
	    cash.Name = "Cash"
	    cash.Value =  50
	    cash.Parent = stats
	    stats.Parent = newPlayer
end
 
 
 
game.Players.ChildAdded:connect(onPlayerEntered)

i tried puting this code in to the zombie

1 if script.Parent.Health == 0 then 2 value = value +1 just dont work

plz any1 help if you do thank you

2 comments

0

Are you defining the value?

0

what do you mean'

2 answers

Heres a script For The NPC:

script.Parent.Humanoid.Died:Connect(function()
       local Players = game:GetService("Players")
       local Player = Players.LocalPlayer -- LocalPlayer is not A Service
       local leaderstats = LocalPlayer.leaderstats
       leaderstats.Cash.Value = leaderstats.Cash.Value + 1
end)

Also fix for leaderstats:

Excepted, leaderstats Parent:

function onPlayerEntered(newPlayer)
        local leaderstats = Instance.new("IntValue")	        
        leaderstats.Name = "leaderstats"
        leaderstats.Parent = newPlayer

        local cash = Instance.new("IntValue")
        cash.Name = "Cash"
        cash.Value =  50
        cash.Parent = stats

game.Players.PlayerAdded:connect(onPlayerEntered)

3 comments

0

You can't like that you need to find the player first. This will give Cash to the whole server.

0

it dosent work the leaderstats diapear btw its first person maybe that?

0

bruh i dont understand

Well, first you need to find the player. Try doing something like this.

local player = () -- you need to find the player with the weapon
while true do
	if script.Parent.Humanoid.Health == 0
		player.leaderstats.Cash.Value = +1
end


And then do everything else yourself cause I can't since I don't have the weapon. You need to do some script in the weapon to check who killed the npc.

1 comment

0

i ummmmmmm dont understand

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