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

For some reason my 'Award points on death' system doesn't work, can someone help?

I put this script inside a NPC with a humanoid inside it and this is a SS script

local plr = game.Players.LocalPlayer

if script.Parent.Humanoid.Health == 0 then
	plr.leaderstats.Currency.Value = plr.leaderstats.Currency.Value + 10
end

2 comments

0

ServerScripts cannot run the local player

0

Also, you should not use an if statement because it will run only once when the script is made. This will cause it to be false at the start and when a player kills the NPC, it wont run again.

1 answer

Add a server script into serverscriptservice and use this code

game:GetService("Players").PlayerAdded:Connect(function(player)
	
	player.CharacterAdded:Connect(function(char)
		
		char:WaitForChild("Humanoid").Died:Connect(function()
			player.leaderstats.Currency.Value += 10
		end)
		
	end)
	
end)

So we are functioning when a player joins and check when the character joins so we can run a function to check when the player dies and when they do we are gonna reward the player some currency

1 comment

0

you didnt even care to explain to a beginner.

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