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

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

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

2 comments

0

I edited the answer

0

Edit: Added code block

1 answer

✓ Accepted answer

[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.

4 comments

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?

0

Answer edited

0

so where do i put it and what type of script do i put it in?

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