#decimal value leaderstat

1 messages · Page 1 of 1 (latest)

crystal wave
#

explanation below

#

This is the leaderstat script

local LeaderboardDataStore = DataStore:GetDataStore("LeaderboardDataStore")

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"

    local Rarity = Instance.new("NumberValue", leaderstats)
    Rarity.Name = "HighestRarity" 

    local Rerolls = Instance.new("NumberValue", leaderstats)
    Rerolls.Name = "Rerolls"

    local UserId = player.Name.." - "..player.UserId

    local success, data = pcall(function()
        return LeaderboardDataStore:GetAsync(UserId)
    end)

    if success and data then
        Rarity.Value = data.Rarity or 0
        Rerolls.Value = data.Rerolls or 0
    else
        Rarity.Value = 1
        Rerolls.Value = 0
    end
end)

game.Players.PlayerRemoving:Connect(function(player)
    local UserId = player.Name.." - "..player.UserId
    local data = {
        Rarity = player.leaderstats.HighestRarity.Value,
        Rerolls = player.leaderstats.Rerolls.Value
    }

    local success, errormessage = pcall(function()
        return LeaderboardDataStore:SetAsync(UserId, data)
    end)

    if not success then
        warn("Failed to save data for "..player.Name.." - "..errormessage)
    else
        print("Successfully saved data for "..player.Name)
    end
end)```
#

and pretty much

#

when i try to change the Rarity leaderstat to a decimal value like 0.1 trough remote event on server it rounds it to 1

#

my goal it to make it actually 0.1

#

as you can see i use numbervalue and i am pretty sure they should support decimals right

gusty dune
#

Show the local script for displaying the numbers

candid socket
#

there prob isnt one

#

oh wait theres remote part we not seeing (or im blind)

crystal wave
#

well i fire it in a local script but the numbers are in server script

candid socket
#

the one u showed is just loading from db

crystal wave
#

yeah

#
        SecretValue.Changed:Connect(function()
        if SecretValue.Value <= 0 then
            print("Error")
        elseif SecretValue.Value <= 285714 then
            ShowRoll:FireClient(Player, "Legacy")
            UnlockIndex:FireClient(Player, "Legacy")
            if RarityLeaderstat.Value <= 3500 then
                RarityLeaderstat.Value = 0.35
            end
        elseif SecretValue.Value <= 769230 then
            ShowRoll:FireClient(Player, "Positive")
            UnlockIndex:FireClient(Player, "Positive")
            if RarityLeaderstat.Value <= 1300 then
                RarityLeaderstat.Value = 0.13
            end
        elseif SecretValue.Value <= 1111111 then
            ShowRoll:FireClient(Player, "Effect")
            UnlockIndex:FireClient(Player, "Effect")
            if RarityLeaderstat.Value <= 900 then
                RarityLeaderstat.Value = 0.09
            end
        elseif SecretValue.Value <= 9900990 then
            ShowRoll:FireClient(Player, "Nothing")
            UnlockIndex:FireClient(Player, "Nothing")
            if RarityLeaderstat.Value <= 100 then
                RarityLeaderstat.Value = 0.01
            end
        elseif SecretValue.Value > 1010101 then
            return
        end
    end)
end)```
#

wait

#

yeah this

#

is the serverscript

#
    ReplicatedStorage.Roll:FireServer(Player)
end)```
#

this is the local script

#

that fires it

#

i dont really think the problem is in these script tho

#

it changes it normally

#

just not into a decimall

#

when it should change to 0.01 it changes to 1

#

and i need it to ofc be 0.01

#

@candid socket

crystal wave
candid socket
crystal wave
#

yeah

#

i use number value and i think it should work with decimals

candid socket
crystal wave
#

not surprised

#

but just like i said the code works

candid socket
#

where did you define rarityleaderstat?

crystal wave
#

the leaderstat changes

candid socket
#

inside player added or smth?

crystal wave
#

well since this is on a server script

#

i had to define it in the function

candid socket
crystal wave
#

because the roll function sends the player

candid socket
#

ik this is partial code

#

but i need to see how you defined it

crystal wave
#
    local leaderstats = Player:WaitForChild("leaderstats")
    local RarityLeaderstat = leaderstats.HighestRarity
    local RerollsLeaderstat = leaderstats.Rerolls
#

right under it

candid socket
#

alright i see

#

so wait

#

is it only after rejoin?

crystal wave
#

no

#

when it changes

candid socket
#

or its instantly turning 0.01 to 1

crystal wave
#

its laready 1

#

yes

candid socket
#

so you see it turn to 0.01 then turn to 1?

crystal wave
#

no

#

its instantly 1

candid socket
#

how fast do u roll

#

after joining

#

just checking if maybe data is failing to load so it sets to 1

#

(datasaving)

crystal wave
#

wait

candid socket
#

unless im looking at wrong leaderstat

crystal wave
#

well you can roll any time

#

it has cooldown of 0.5 seconds

candid socket
#

could you first add more prints?

candid socket
#

just to be sure

crystal wave
#

and when you roll you have a chance to change your leaderstat to 0.01

#

its not about loading

candid socket
crystal wave
#

i dont think you understand

candid socket
#

it definetly isnt supposed to be rounding

crystal wave
#

you can fire roll any time

candid socket
#

so i feel like other script is doing that

crystal wave
#

and when you roll it can set your leaderstat to 0.01 which ofc it will make it 1

#

also even if it would round im pretty sure it will round down to 0

#

i think it works wait

crystal wave
#

i think i found something else as a probelm

keen oyster
#

anyway numbervalue shows 2 decimal places for values <1000

crystal wave
#

for some reason highest leaderstat doesnt save

#
local LeaderboardDataStore = DataStore:GetDataStore("LeaderboardDataStore")

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"

    local Highest = Instance.new("NumberValue", leaderstats)
    Highest.Name = "Highest" 

    local Rerolls = Instance.new("NumberValue", leaderstats)
    Rerolls.Name = "Rerolls"

    local UserId = player.Name.." - "..player.UserId

    local success, data = pcall(function()
        return LeaderboardDataStore:GetAsync(UserId)
    end)

    if success and data then
        Highest.Value = data.Highest or 0
        Rerolls.Value = data.Rerolls or 0
    else
        Highest.Value = 1
        Rerolls.Value = 0
    end
end)

game.Players.PlayerRemoving:Connect(function(player)
    local UserId = player.Name.." - "..player.UserId
    local data = {
        Rarity = player.leaderstats.Highest.Value,
        Rerolls = player.leaderstats.Rerolls.Value
    }

    local success, errormessage = pcall(function()
        return LeaderboardDataStore:SetAsync(UserId, data)
    end)

    if not success then
        warn("Failed to save data for "..player.Name.." - "..errormessage)
    else
        print("Successfully saved data for "..player.Name)
    end
end)```
#

the highest stat doesnt load

#

it says saved data

#

but when loading it doesnt load the highest data

#

but does rerolls

#

wait

#

ok

#

yeah im dumb

candid socket
#

you never changed it did u

crystal wave
#

well nwm

candid socket
#

/on client

crystal wave
#

what

keen oyster
#

probably changing it on client ya

crystal wave
#

what client

#

no if u loook at line 32 i forgor to rename rarity to highest

#

that it

#

the whole problem

#

one more thing guys
if i do if RarityLeaderstat.Value <= 100 and not 0.35 or 0.13 or 0.09 then
does it do the function only if the value is below 100 and isnt any of the other numbers mentioned? just to confirm it works like i think

#

@candid socket

#

@keen oyster

#

nwm

short jettyBOT
#

studio** You are now Level 15! **studio