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

why does the leaderstat not change on death?

So I am making this game and when I kill the npc it's suppose to give you a point. can anyone fix this pls?

local humanoid = script.Parent:FindFirstChild("Humanoid")
local player = game.Players:FindFirstChild(humanoid.Parent.Name)

if humanoid.Health == 0 then
		player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 10 
		player.leaderstats.Coins.Value = player.leaderstats.Levels.Value + 1 
	end

3 comments

0

Boredlake I did what you asked but it just gives me an error about the leaderstats not working

0

Workspace.Dummy.Points on Death:5: attempt to index nil with 'leaderstats' - Server - Points on Death:5

0

local function onPlayerJoin(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local coins = Instance.new("IntValue") coins.Name = "Coins" coins.Value = 0 coins.Parent = leaderstats end game.Players.PlayerAdded:Connect(onPlayerJoin)

1 answer

The script you provided would only give a point to the player when the player dies as soon as the server is made, which I assume is not what you are trying to achieve. To fix this you would need to define the humanoid as the humanoid of the NPC and the player as game.Players:GetPlayerFromCharacter(script.Parent), and rather than checking if humanoid.Health == 0 it should be humanoid.Died:Connect(function()

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