Help with rebirth gui not updating

ok so basically im making a rebirth thing right and i want the cost and label to automatically update
but i have to click to make it update the price and stuff

robloxapp-20240313-1550033.wmv (317.9 KB)

local parent = script.Parent
local button1 = parent.Button
local button2 = button1.Buttons
local button = button2.Button
local title = button1.Label
local pricelabel = button2.Button.Move.Price
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvents = replicatedStorage:WaitForChild("ClickRemotes")
local rebirthEvent = remoteEvents:WaitForChild("Rebirth")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")

button.MouseButton1Up:Connect(function()
	local clicks = leaderstats.Clicks.Value
	local rebirths = leaderstats.Rebirths.Value
	local rebirthsAmount = script.Parent:GetAttribute("Rebirth")
	local cost = script.Parent:GetAttribute("Cost") * (rebirths / 1000)
	local gemsGiven = rebirthsAmount * 10

	if clicks >= cost then
		rebirthEvent:FireServer(rebirthsAmount, gemsGiven)
		-- Update price label text
		pricelabel.Text = tostring(cost)
		-- Update title
		title.Text = "Rebirth x" .. tostring(rebirthsAmount)
	end
end)

I’m guessing you want to make it update automatically?

If yes, here’s a modified version of your script that will update it.

local parent = script.Parent
local button1 = parent.Button
local button2 = button1.Buttons
local button = button2.Button
local title = button1.Label
local pricelabel = button2.Button.Move.Price
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvents = replicatedStorage:WaitForChild("ClickRemotes")
local rebirthEvent = remoteEvents:WaitForChild("Rebirth")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")

local function updatePrice()
	local clicks = leaderstats.Clicks.Value
	local rebirths = leaderstats.Rebirths.Value
	local rebirthsAmount = script.Parent:GetAttribute("Rebirth")
	local cost = script.Parent:GetAttribute("Cost") * (rebirths / 1000)
	local gemsGiven = rebirthsAmount * 10

	if clicks >= cost then
		rebirthEvent:FireServer(rebirthsAmount, gemsGiven)
		-- Update price label text
		pricelabel.Text = tostring(cost)
		-- Update title
		title.Text = "Rebirth x" .. tostring(rebirthsAmount)
	end
end

button.MouseButton1Up:Connect(updatePrice)
leaderstats:WaitForChild("Rebirths"):GetPropertyChangedSignal("Value"):Connect(updatePrice)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.