Do me a favor though. Try putting a simple print("THIS IS A TEST")
line at the top of your rebirth script where you detect when it’s changed and clamp it.
Make sure it’s running. Some places do not run script code.
Do me a favor though. Try putting a simple print("THIS IS A TEST")
line at the top of your rebirth script where you detect when it’s changed and clamp it.
Make sure it’s running. Some places do not run script code.
he is showing up
This seems really simple if that’s the problem I think you’re having :
Rebirth.Changed:Connect(function()
if Rebirth.Value > 10 then
Rebirth.Value = 10
elseif Rebirth.Value < 1 then
Rebirth.Value = 1
end
end)
Hope It Helped.
Huh.
Well we can confirm it is indeed detecting the script.
You should use a print message in the Changed function that will print out the Rebirth Value to detect that it is being changed and what the value is. After the clamp code, have it print the Rebirth Value after it’s clamped.
That data should tell us if it’s actually clamping the value.
More like this:
local rebirth = script.Parent
rebirth.Changed:Connect(function()
print("Before", rebirth.Value)
rebirth.Value = math.clamp(value,0,2000)
print("After", rebirth.Value)
end)
Whats the purpose of the .Changed function?
Just clamp it where you set it
If you have a server script where youre adding 100 to it, clamp the value there
rebirth.Value += 100 --before
---------------
rebirth.Value = math.clamp(rebirth.Value + 100,0,1000000000) --after
Good question. Allow me to answer.
The Changed event will detect when the Value is changed, anywhere, any time, by any function.
It saves you the trouble of hunting down every place where you manually change the Value, and putting a clamp in every single spot where that happens.
It is, overall, much more efficient coding and is recommended. As per DNR (Do Not Repeat) programming concepts.
Its still asynchronous and could cause issues with complexity and reliability
DNR exists to be a convenience and to prevent errors, however in a case like this after 30 posts it might be an idea to, even only temporarily, use a simpler approach to root out misunderstandings and/or bugs because Im not so sure its acting as a convenience
Instead of clamping the value when it’s changed, you can find where in your code you actually set this value, and clamp it while setting. This prevents overseen headaches and is better practice. By doing this, you’re saying “Hey, keep my rebirths between 0 and 1 billion!” instead of “Hey, when my Rebirths value is set to some arbitrary number, externally clamp it by setting it again to my liking.”
As mentioned numerous times in this thread, a way to return a constrained number easily is to use the math.clamp
function:
math.clamp(number, minimum, maximum)
Instead of just ingesting this code directly and pasting it into yours, you should visit the documentation for this function to find out what it actually does.
the print (“Hello world!”) had worked a few comments ago, but now the rebirth value didn’t work
In that case, I think the problem is buried in how the things in your Explorer are being structured. The problem isn’t in the code. The problem is with where you’re putting the scripts, how you’re cloning the Stats folder/Rebirth Value, and where the clone is being placed.
how can I transfer this script to the leaderstats script without changing the saved values of the players?
You could use the deprecated IntConstrainedValue object which works exactly as you want (But I don’t recommend it since is deprecated, it doesn’t have any issues though)
To get this object execute this in the command bar:
Instance.new("IntConstrainedValue", workspace)
I had tried to use it before making this post but it limited the rebirth value to only 10
Did you change the MaxValue and MinValue?
yes i tried to switch to 1 Billion but still limited to 10
I will try again and warn you
The issue is with this script, is creating ew values instead of cloning the folder which contains the script inside Rebirths. Make sure to clone the folder and parent it to the player. @P1xelR3n Said it and yeah he is correct.