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

How can I put MaxValue on leaderstats?

I've used IntConstainedValue once and said it's not recommended, so what should I do?

function onPlayerEntered(plr)
	wait(.5)
	local stats = Instance.new("Folder",plr)
	stats.Name = "leaderstats"

	local Money= Instance.new("IntValue"stats)
	
	Money.Name = "Money"
	Money.Value = 0
    -- Ex.: Money.MaxValue.Value = 1000 This with IntConstainedValue but, and without?

end

game.Players.ChildAdded:connect(onPlayerEntered)

1 answer

✓ Accepted answer

###IntConstrainedValue objects are deprecated. You can add a changed event, which will check if the value goes over max value.

game:GetService("Players").PlayerAdded:Connect(function(plr)
     local stats = Instance.new("Folder")
    stats.Name = "leaderstats"
    stats.Parent = plr

    local Money = Instance.new("IntValue")
    Money.Name = "Money"
    Money.Value = 0
    Money.Parent = plr
    
    Money.Changed:Connect(function(newVal)
        if newVal > 1000 then 
            plr["leaderstats"]["Money"].Value = 999 -- to whatever value lol
        end
    end)
end)

###On a side note, you should switch to Connect, as connect is deprecated. The parent argument to Instance.new is also deprecated, assign the parent in another line.

###You shouldn't be using ChildAdded, but PlayerAdded, as ChildAdded is prone to script failure, should an object that isn't a Player object be added to the Players service.

4 comments

0

If the TextLabel.Text is showing so much money that I have (already in the limit) there I make more money beyond the maximum, will TextLabel.Text show this value beyond the limit or will it continue in Money that I have? (This is already in the limit) Of course I will continue with the money I have (limit), but I want to know if it will show that it has gone from limit for a second and return to n

0

normal'

0

Have a changed event for the IntValue, and have the TextLabel change text.

0

It was not my question, but I'll test it myself, thanks!

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