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

How do you make the leaderstats not go below zero? [That is FE compatible]

I have this problem that when you buy something. You can keep buying, even when it is in the negatives. How do I stop this?

5 comments

0

Use your brain lol

0

I don't have one, lol.

0

Buy a brain, lol.

0

Can you post your script please?

0

Yes

1 answer

I forgot to post the script. Here you go. (This doesn't work anymore because of FE I am guessing)

function CheckPoints(Points)
    if Points.Value < 0 then
    Points.Value = 0
    end
end)

game.Players.PlayerAdded:connect(function(Player) --anonymous function
    local ls = Instance.new("Configuration", Player)
    ls.Name = "leaderstats"
    local Points = Instance.new("IntValue", ls) -- classname, parent
    Points.Name = "Money"
    Points.Changed:connect(function() CheckPoints(Points) end)
end)

EDIT: This is the script of when you click a button, then a certain amount of money gets taken away from your balance (I hired someone to do this):

script.Parent.ClickDetector.MouseClick:connect(function(player)
	local players = game.Players:FindFirstChild(player.Name)
			local clicks = players:FindFirstChild("leaderstats")["Money"]
				clicks.Value = clicks.Value -0.1
end)

This is the leaderboard stats itself:


local ds = game:GetService("DataStoreService"):GetDataStore("stats")
local stats={"Money"}
game.Players.PlayerAdded:connect(function(plyr)
	local a=Instance.new("NumberValue")
	a.Parent=plyr
	a.Name="leaderstats"
	for i=1,#stats do
		local Wins=Instance.new("NumberValue")
		Wins.Parent=a
		Wins.Value=0
		Wins.Name=stats[i]
	end
	local child=plyr.leaderstats:GetChildren()
	for i=1, #child do
		child[i].Value=ds:GetAsync(plyr.userId..child[i].Name)
	end
end)

game.Players.PlayerRemoving:connect(function(plyr)
	local child=plyr.leaderstats:GetChildren()
	for i=1, #child do
		child[i].Value=ds:SetAsync(plyr.userId..child[i].Name,child[i].Value)
	end
end)


I hope this helps

2 comments

0

is there a script of where you are buying an item? If so could you post that as well?

0

Sure.

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