#Rebirth CalculatePrice Function

52 messages · Page 1 of 1 (latest)

loud atlas
#

My CalculatePrice function doesent work ```local RebirthsConfig = {}

RebirthsConfig.BasePrice = 800
RebirthsConfig.IncreasePerRebirth = 175

function RebirthsConfig.CalculatePrice(currentRebirth: number, amountOfRebirths: number?)
amountOfRebirths = if amountOfRebirths then amountOfRebirths else 1

local price = 0
local rebirths = 0
while (rebirths < amountOfRebirths) do
    price += RebirthsConfig.BasePrice + ( (rebirths + currentRebirth) * RebirthsConfig.IncreasePerRebirth )
    rebirths += 1
end

return price

end

RebirthsConfig.Buttons = {
["1"] = {
Price = 0

},
["5"] = {
    Price = 0
},

["10"] = {
    Price = 0
},
["50"] = {
    Price = 10
},
["250"] = {
    Price = 2_500
},

}

function RebirthsConfig.HasButtonUnlocked(playerData, rebirthButton: number)
local buttonConfig = RebirthsConfig.Buttons[rebirthButton]
if not buttonConfig then return false end

return playerData.RebirthButtons[rebirthButton]

end

return RebirthsConfig```

Error: 20:23:03.916 ReplicatedStorage.Config.Rebirths:12: attempt to perform arithmetic (add) on number and table - Client - Rebirths:12

coarse jay
#

is currentRebirth definitely a number

loud atlas
#

i made a state manager and after that everyhting stopped working with that same error

loud atlas
#

can anyone help

coarse jay
#

thats the only thing that could really not be a number

#

check to make sure that youre definitely passing a number every time

loud atlas
coarse jay
#

lets see the state manager script

loud atlas
# coarse jay lets see the state manager script
local Remotes = ReplicatedStorage.Remotes
local Template = require(ReplicatedStorage.PlayerData.Template)

local isDataLoaded = false
local PlayerData: Template.PlayerData

local function LoadData()
    if isDataLoaded then return end

    while not PlayerData do
        PlayerData = Remotes.GetAllData:InvokeServer()
        task.wait(1)
    end

    isDataLoaded = true
end

LoadData()

local State = {}

function State.GetData(): Template.PlayerData
    while not isDataLoaded do
        task.wait(0.5)
    end

    return PlayerData
end

Remotes.PurchaseJump.OnClientEvent:Connect(function(jump)
    PlayerData.Jumps = jump
end)

Remotes.Updateclicks.OnClientEvent:Connect(function(amount)
    PlayerData.Clicks = amount
end)

Remotes.Updategems.OnClientEvent:Connect(function(amount)
    PlayerData.Gems = amount
end)

Remotes.Updaterebirths.OnClientEvent:Connect(function(amount)
    PlayerData.Rebirths = amount
end)

Remotes.UpdateRebirthButton.OnClientEvent:Connect(function(rebirth: string, isUnlocked: boolean)
    PlayerData.RebirthButtons[rebirth] = isUnlocked
end)

Remotes.UpdateAutoClicker.OnClientEvent:Connect(function(autoClicker: "Regular" | "Fast", mode: boolean)
    PlayerData.Auto[autoClicker].Active = mode
end)


return State```
coarse jay
#

show me where you do RebirthsConfig.CalculatePrice

coarse jay
#

no like show me code that calls that function

loud atlas
#

ah mb

loud atlas
# coarse jay no like show me code that calls that function
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage.Remotes
local PlayerData = require(ServerScriptService.Playerdata.Manager)
local RebirthConfig = require(ReplicatedStorage.Config.Rebirths)

local Rebirth = {}

function Rebirth.Rebirth(player: Player, amount: number?)
    amount = if amount then amount else 1
    
    local profile = PlayerData.Profiles[player]
    if not profile then return "No profile!"end
    
    local currentRebirth = profile.Data.Rebirths
    local price = RebirthConfig.CalculatePrice(currentRebirth, amount)
    
    local canAfford = profile.Data.Clicks >= price
    if not canAfford then return "Cannot afford "..price.."!" end
    
    PlayerData.AdjustRebirths(player, amount)
    PlayerData.AdjustClicks(player, -profile.Data.Clicks)
    PlayerData.AdjustGems(player, 10 * amount)
    return "You Rebirthed "..amount.." times!"
end

print("Passed The Rebirth Function")

function Rebirth.UnlockButton(player: Player, rebirthButton: string)
    local profile = PlayerData.Profiles[player]
    if not profile then return "No profile!" end
    
    local price = RebirthConfig.Buttons[rebirthButton].Price
    local canAfford = profile.Data.Gems >= price
    if not canAfford then return "Cannot afford "..price.."!" end
    
    local isUnlocked = RebirthConfig.HasButtonUnlocked(profile.Data, tonumber(rebirthButton))
    if isUnlocked then return "Already unlocked!" end
    
    PlayerData.AdjustGems(player, -price)
    profile.Data.RebirthButtons[rebirthButton] = true
    Remotes.UpdateRebirthButton:FireClient(player, rebirthButton, true)
end

print("Passed The UnlockButton Function")

Remotes.RequestRebirth.OnServerEvent:Connect(function(player: Player, rebirth: string)
    rebirth = tonumber(rebirth)
    if not rebirth then return end
    Rebirth.Rebirth(player, rebirth)
end)

return Rebirth```
#

Should be called in this script

coarse jay
#

and profile.Data.Rebirths is definitely a number and not a table

coarse jay
#

make sure cuz that seems like the only thing it could be

loud atlas
coarse jay
#

PlayerData.Profiles[player]

loud atlas
#

it might be my template script

#

im new to coding im being stupid rn

loud atlas
coarse jay
#

you might be setting profile.Data.Rebirths to be a table

loud atlas
#

local RebirthConfig = require(ReplicatedStorage.Config.Rebirths)

local DEFAULT_AUTO_INFO = {
    Active = false,
    Duration = 0
}

local DEFAULT_REBIRTH_BUTTONS = {}
for rebirth, info in RebirthConfig.Buttons do
    DEFAULT_REBIRTH_BUTTONS[rebirth] = info.Price == 0
end
    
local Template = {
    Clicks = 0,
    Gems = 0,
    Rebirths = 0,
Auto = {
    Fast = DEFAULT_AUTO_INFO, 
    Regular = DEFAULT_AUTO_INFO
   },
   RebirthButtons = DEFAULT_REBIRTH_BUTTONS,
   Jumps = 1
}

export type PlayerData = typeof(Template)

return Template```
#

template script dont think its that

#

bruh

#

it wont let me send my data script

#

local Remotes = ReplicatedStorage.Remotes

local Manager = {}

Manager.Profiles = {}

function Manager.AdjustClicks(player: Player, amount:number)
    local profile = Manager.Profiles[player]
    if not profile then return end
    profile.Data.Clicks += amount
    player.leaderstats.Clicks.Value = profile.Data.Clicks
    Remotes.Updateclicks:FireClient(player, profile.Data.Clicks)
end

function Manager.AdjustGems(player: Player, amount:number)
    local profile = Manager.Profiles[player]
    if not profile then return end
    profile.Data.Gems += amount
    player.leaderstats.Gems.Value = profile.Data.Gems
    Remotes.Updategems:FireClient(player, profile.Data.Gems)
end

function Manager.AdjustRebirths(player: Player, amount:number)
    local profile = Manager.Profiles[player]
    if not profile then return end
    profile.Data.Rebirths += amount
    player.leaderstats.Rebirths.Value = profile.Data.Rebirths
    Remotes.Updaterebirths:FireClient(player, profile.Data.Rebirths)
end


local function GetData(player: Player, directory: astring)
    local profile = Manager.Profiles[player]
    if not profile then return end
    return profile.Data[directory]
end

local function GetallData(player: Player)
    local profile = Manager.Profiles[player]
    if not profile then return end
    return profile.Data
    
end
local function GetAutoClickMode(player: Player, buttonType: "Fast" | "Regular")
    local profile = Manager.Profiles[player]
    if not profile then return end
    return profile.Data.Auto[buttonType].Active
end

Remotes.GetData.OnServerInvoke = GetData
Remotes.GetAllData.OnServerInvoke = GetallData
Remotes.GetAutoClickMode.OnServerInvoke = GetAutoClickMode


return Manager
``` Or my manager script
#

one of them

coarse jay
#

i need manager

#

yeah

loud atlas
#

thought so

#

i forgot about my manager script

coarse jay
#

whats this local function GetData(player: Player, directory: astring)
local profile = Manager.Profiles[player]
if not profile then return end
return profile.Data[directory]
end

calm briarBOT
#

studio** You are now Level 12! **studio

loud atlas
#

what script sorry

#

oh wait

#

im ngl i cant even remember making that function

#

oh hold up

#

yh no idk what thats used for

coarse jay
#

idk if thats it i just notice that its giving a directory

#

so somewhere you might be setting data to a table there

#

see the difference here

local function GetData(player: Player, directory: astring)
    local profile = Manager.Profiles[player]
    if not profile then return end
    return profile.Data[directory]
end

local function GetallData(player: Player)
    local profile = Manager.Profiles[player]
    if not profile then return end
    return profile.Data
    
end
loud atlas
#

i must be calling getdata dk where tho

#

ik getalldata is being called in my state manager script

#

Ok its getting called in one of my other script

#

that was also getting a error similar

#

its something to do with the getdata function dk what tho