Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

why does the leaderstat not change on death?

Asked by
VipDanT 10
2 years ago

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
0
Boredlake I did what you asked but it just gives me an error about the leaderstats not working VipDanT 10 — 2y
0
Workspace.Dummy.Points on Death:5: attempt to index nil with 'leaderstats' - Server - Points on Death:5 VipDanT 10 — 2y
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) VipDanT 10 — 2y

1 answer

Log in to vote
0
Answered by
boredlake 256 Moderation Voter
2 years ago
Edited 2 years ago

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()

Ad

Answer this question