#Every value from data.RebirthsButtons is marked as false?

1 messages · Page 1 of 1 (latest)

alpine vapor
#

Client:


local FormatNumber = require(ReplicatedStorage.Libs.FormatNumber.Simple)
local Remotes = ReplicatedStorage.Remotes
local RebirthConfig = require(ReplicatedStorage.Config.Rebirths)

local Player = game:GetService("Players").LocalPlayer
local PlayerGui = Player.PlayerGui 

local ButtonGui = PlayerGui:WaitForChild("Main")
local OpenButton = ButtonGui.Main.loop

local Gui = PlayerGui:WaitForChild("Rebirth")
local Frame = Gui.Frame

local Rebirths = Frame.RB
local ExitButton = Frame.Close
local Container = Frame.Container

local template = Container.RBone
local UnlimitedButton = Container.RBinf
local REBIRTH_BUTTON_COST_TEMPLATE = "AMOUNT"
local REBIRTH_BUTTON_REBIRTHS_TEMPLATE = "AMOUNT Rebirths"

local data = {
    Rebirths = 0,
    RebirthsButtons = {}
}

local function UpdateButtons()
    for _, child in Container:GetChildren() do
        if not child:IsA("Frame") or child.Name == "RBone" or child.Name == "RBInf" then return end
        local clone: typeof(template) = child
        
        clone.Visible = data.RebirthsButtons[clone.Name]
    end
end

local function UpdateButtonCosts()
    for _, child in Container:GetChildren() do
        if not child:IsA("Frame") then return end
        local clone: typeof(template) = child
        
        local rebirths = tonumber(clone.Name)
        local cost = RebirthConfig.CalculatePrice(data.Rebirths, rebirths)
        clone.Buy.Text = FormatNumber.FormatCompact(cost)
    end
end```
#

`local function UpdateButtonBuyable(amount: number)
for _, child in Container:GetChildren() do
if not child:IsA("Frame") then return end
local clone: typeof(template) = child

    local rebirths = tonumber(clone.Name)
    local cost = RebirthConfig.CalculatePrice(data.Rebirths, rebirths)
    local canAfford = amount >= cost
    
    clone.Buy.BackgroundColor3 = if canAfford then Color3.fromRGB(148, 255, 131) else Color3.fromRGB(200, 200, 200)
end

end

local function GenerateButton(rebirths: string)
local isUnlocked = RebirthConfig.HasButtonsUnlocked(data, tonumber(rebirths))
local clone = template:Clone()
clone.Parent = Container
clone.Name = rebirths
clone.Visible = isUnlocked
clone.LayoutOrder = tonumber(rebirths)
clone.Rebirths.Text = REBIRTH_BUTTON_REBIRTHS_TEMPLATE:gsub("AMOUNT", FormatNumber.FormatCompact(tonumber(rebirths)))
clone.Buy.MouseButton1Up:Connect(function()
Remotes.RequestRebirths:FireServer(rebirths)
end)
end

for rebirths, info in RebirthConfig.Buttons do
GenerateButton(rebirths)
end

local function UpdateRebirths(amount: number)
Rebirths.Text = FormatNumber.FormatCompact(amount)

data.Rebirths = amount
UpdateButtonCosts()

end

Remotes.UpdateClicks.OnClientEvent:Connect(UpdateButtonBuyable)
UpdateRebirths(Remotes.GetData:InvokeServer("Rebirths"))
Remotes.UpdateRebirths.OnClientEvent:Connect(UpdateRebirths)
Remotes.UpdateRebirthButtons.OnClientEvent:Connect(function(rebirth: string, isUnlocked: boolean)
data.RebirthsButtons[rebirth] = isUnlocked
UpdateButtons()
end)

OpenButton.MouseButton1Up:Connect(function()
Gui.Enabled = not Gui.Enabled
end)

ExitButton.MouseButton1Up:Connect(function()
Gui.Enabled = false
end)

UpdateButtonCosts()
UpdateButtonBuyable(Remotes.GetData:InvokeServer("Clicks"))

data.RebirthsButtons = Remotes.GetData:InvokeServer("RebirthButtons")
UpdateButtons()`

#

Server:

`local remotes = game:GetService("ReplicatedStorage").Remotes

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
},
["20"] = {
Price = 0
},
["50"] = {
Price = 500
},
["75"] = {
Price = 750
},
["100"] = {
Price = 1_000
},
["150"] = {
Price = 1_500
}
}

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

return playerData.RebirthsButtons[rebirthButton]

end

return RebirthsConfig
`

#

(i know it’s very long to read but I couldn’t find where the issue came from and I can’t post it as a txt 😭)

alpine vapor
#

BOOSTING THE POST

unkempt obsidianBOT
#

studio** You are now Level 1! **studio

gray atlas
alpine vapor
#

It’s in the server since it can get all tables from the server (RebirthsConfig.Buttons)

gray atlas
alpine vapor
#

If i remember correctly it gets the table from the server later on during the script, so..

#

Yea

gray atlas
#

i.e doing instance:setattribute will replicate to all clients, but doing tbl={data} will not do anything

gray atlas
# alpine vapor Client: ```local ReplicatedStorage = game:GetService("ReplicatedStorage") loca...

unless there's more code to this, i don't see anything that will bring in any values to data.RebirthsButtons in this specific script. i'm assuming the issue is in UpdateButtons or UpdateButtonCosts ```lua
local data = {
Rebirths = 0,
RebirthsButtons = {}
}

local function UpdateButtons()
for _, child in Container:GetChildren() do
if not child:IsA("Frame") or child.Name == "RBone" or child.Name == "RBInf" then return end
local clone: typeof(template) = child

    clone.Visible = data.RebirthsButtons[clone.Name]
end

end

local function UpdateButtonCosts()
for _, child in Container:GetChildren() do
if not child:IsA("Frame") then return end
local clone: typeof(template) = child

    local rebirths = tonumber(clone.Name)
    local cost = RebirthConfig.CalculatePrice(data.Rebirths, rebirths)
    clone.Buy.Text = FormatNumber.FormatCompact(cost)
end

end```

#

tbh depending on how you've structured everything, you can probably just change the client's playergui directly from the server and that'll do the job good enough 👍

alpine vapor
#

Ohhh