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

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

Asked by 2 years ago
Edited by Leamir 2 years 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 1287 — 2y
0
Edit: Added code block Leamir 3138 — 2y

1 answer

Log in to vote
0
Answered by
sleazel 1287 Moderation Voter
2 years ago
Edited 2 years 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 — 2y
0
Answer edited sleazel 1287 — 2y
0
The method is Humanoid:TakeDamage() - See https://developer.roblox.com/en-us/api-reference/function/Humanoid/TakeDamage Leamir 3138 — 2y
0
so where do i put it and what type of script do i put it in? xGlacier101x 9 — 2y
Ad

Answer this question