Ad
Log in to vote
1

How do you make a leaderstat damage system? Pls help!;-;

Asked by 16 days ago
Edited by Leamir 15 days ago

I tried to make a system that when the leaderstats reaches zero, the player takes damage. I've tried lots of methods, bit it still don't work

local Players = game:GetService("Players")
local plr = Players.LocalPlayer

local PlayerMoneyValue = plr.leaderstats.Reality.Value

while true do
    wait(0.5)
    if PlayerMoneyValue < 1 then
        plr.Parent.Humanoid:Takedamage(10)
    end
end
0
I edited the answer sleazel 1282 — 15d
0
Edit: Added code block Leamir 3088 — 15d

1 answer

Log in to vote
0
Answered by
sleazel 1282 Moderation Voter
16 days ago
Edited 15 days ago

[EDIT: corrected humanoid damage] By doing this:

local PlayerMoneyValue = plr.leaderstats.Reality.Value

You are only saving INITIAL money value to PlayerMoneyValue variable. To make this script work, you need to keep a reference to the intValue object, like this:

local PlayerMoneyValue = plr.leaderstats.Reality

Only then You can get the CURRENT money value inside the loop. Notice how I added .Value here. This way you make script to recheck the amount on each iteration:

while true do wait(0.5) 
    if PlayerMoneyValue.Value < 1 then
        local char = plr.Character
        if not char then continue end    
        char.Humanoid:Takedamage(10)
    end
end

I hope this helps.

0
Uhh but it still don't work! so i suppose i put it in the wrong place, do you know where to put it cuz serverscriptservice don't do the trick? xGlacier101x 9 — 15d
0
Answer edited sleazel 1282 — 15d
0
The method is Humanoid:TakeDamage() - See https://developer.roblox.com/en-us/api-reference/function/Humanoid/TakeDamage Leamir 3088 — 15d
0
so where do i put it and what type of script do i put it in? xGlacier101x 9 — 15d
Ad

Answer this question