Ok so I am trying to make a script where if a player has 1000 Time then it adds one Flex Point. I was able to create one that subtracts time and adds a Flex Point. But how would I make it keep the Time and still add a Flex Point everytime they get 1000.
Ex My Time is 2347 then I should get 2 flex point. Ten days later its now 3000 I should get one Flex Point bringing my total to 3. It should not be everytime I touch it with over 1000 I get 1.
Old Script (Its not at all relivent but you can base the script off it)
local part = script.Parent
local players = game:GetService("Players")
part.Touched:Connect(function(hit)
local touchPlayer = game.Players:GetPlayerFromCharacter(hit.Parent)
if touchPlayer.leaderstats.TIME <= 1000 then
touchPlayer.leaderstats.TIME -= 1000
touchPlayer.leaderstats.Flex_Points += 1
end
end)
I notice this might be confusing. Ask me some quetions if you like.
I get what your trying to do I’m just trying to think of the easiest solution without complicating your code to where its difficult to use
1 Like
Yes same I thought of a way with If then statments but then It would be a infinite loop.
Again that was the old script me and my team dont want to do that anymore.
So there time wont be subtracted? will they use flex points like to buy things?
1 Like
Yes they will in the near future.
Yes, there time will stay the same
Is this what you wanted?
local part = script.Parent
local players = game:GetService("Players")
part.Touched:Connect(function(hit)
local touchPlayer = game.Players:GetPlayerFromCharacter(hit.Parent)
if not touchPlayer then
return
end
local stats = touchPlayer.leaderstats
stats.Flex_Points.Value = math.floor(stats.TIME.Value/1000)
end)
Basically it sets your Flex points to be the Time value divided by 1000 and then floored. So if you had 2500, it would set it to 2, because 2500 / 1000 is 2.5 and floored is 2.
math.floor
basically just gives you the lowest whole number of a number
print(math.floor(2.1)) -- prints 2
print(math.floor(2.99)) -- prints 2
print(math.floor(3.01)) -- prints 3
2 Likes
Im thinking you can make a hidden level system that will store 2 things
TimeReached // which would act as the Experience
AmountOfFlexPointsEarned // which would act as the level
but this will only work if Time reached bench mark is always 1k and they only receive 1 point each time timereached reaches 1k
then u will wait till time reached has surpassed AmountOfFlexpointsEarned * 1000
and give a point and add onto AmountOfFlexpointsEarned
that’s pretty much my idea
Yes something like that. Testing it now.
So it wont round up?
Correct, so even you had 2900, it would still give you 2 because of how math.floor
works, I editted my post to show some examples
1 Like
would it still work if Flex_Points
is being used as a currency and depleting
1 Like
The thing is you said that time is not decremented when the flex points are converted, so wouldn’t it keep giving the same flex_points regardless? I think you may need another value that keeps track of the time as well but is decremented when yuo need to do flex points stuff
2 Likes
What?
Could you resay that I don’t understand a word.
Basically, I think in order for you to do what is needed, you need another value that also keeps track of the time you have, but this one can be decremented for usage.
Hypothetical example
local part = script.Parent
local players = game:GetService("Players")
part.Touched:Connect(function(hit)
local touchPlayer = game.Players:GetPlayerFromCharacter(hit.Parent)
local toGive = math.floor(stats.TIME.Value/1000)
if not touchPlayer or toGive == 0 then
return
end
local stats = touchPlayer.leaderstats
stats.Flex_Points.Value += toGive
stats.Flex_Points_Time.Value -= (toGive * 1000)
end)
Where Flex_Points_Time
is something that also keeps the time but handles decrementing for what we need to do
1 Like
Is this the only way? Or is there another option?
There is probably another way to do, but right now it’s late at night and I’m not sure what it could be, that’s the best I could think of
1 Like
Ok, Great option but I really would not like to create a new value.