Gui Button Visible Help

Basically, I want to make a text button visible only if the player has enough rebirths. However, it only becomes visible when the amount of rebirths changes, not when the player joins. Can I have some help with this?

-- Configurables
local rebamount = 3 -- How many rebirths this gives
local amtneed = 3 -- How many rebirths needed to see the button
local rebmult = 250 -- How much it should cost, multiplied by the amount of rebirths (Make this cheaper than the last one)

-- Don't change these, non-configurables
local btn = script.Parent
local player = game.Players.LocalPlayer
local leader = player:WaitForChild("leaderstats")
local rebirths = leader:WaitForChild("Rebirths")
local coins = leader:WaitForChild("Coins")
local label = script.Parent
local amount = 100
local rem = game.ReplicatedStorage:WaitForChild("RebirthEvent")
label.Visible = false

game.Players.PlayerAdded:Connect(function()
	amount = rebirths.Value * rebmult
	if rebirths.Value >= amtneed then
		label.Visible = true
		label.Text = "Buy "..rebamount.." Rebirths for: "..amount.." Coins"
	end
end)

rebirths.Changed:Connect(function()
	amount = rebirths.Value * rebmult
	if rebirths.Value >= amtneed then
		label.Visible = true
		label.Text = "Buy "..rebamount.." Rebirths for: "..amount.." Coins"
	end
end)

btn.MouseButton1Click:Connect(function()
	if coins.Value >= amount then
		rem:FireServer(rebamount, amount)
	else
		label.Text = "Not enough coins!"
		wait(3)
		label.Text = "Buy "..rebamount.." Rebirths for: "..amount.." Coins"
	end
end)

Thanks in advance :slight_smile:

I do believe this will work, but if it doesn’t maybe try using GetPropertyChangedSingal

Edit: Just saw that you’re changing amount instead of amtneed. Or am I misunderstanding something?

so game.Players.PlayerAdded only fires when another player joins in a local script.

take

amount = rebirths.Value * rebmult
if rebirths.Value >= amtneed then
label.Visible = true
label.Text = “Buy “…rebamount…” Rebirths for: “…amount…” Coins”
end

out of the playerAdded function, and put it standalone to run at the end.

No, unfortunately doesn’t work. I don’t see what you changed though?

Are there any errors in the output?

Ohhh, makes sense. Should I fire a remote event when the player joins…?

No errors in the output, just only shows the first button

I edited my initial reply, if you’re still a little confused lmk.

Worked, thank you so much! I never knew that it activated only when someone else joins, but I guess it makes sense :laughing:

haha, no problem! If you was doing it server-side it would work, but client side (LocalScript) only fires that when another player joins, that isnt the client player.

1 Like

also, @RealMysticall as @AridTheDev put, you should use a GetPropertyChangedSignal rather than .Changed since .Changed will check if anything of the properties of “rebirths” is changed, using a GetPropertyChangedSignal you can detect if only the value is changed and then it’ll fire.
rebirths:GetPropertyChangedSignal("Value"):Connect(function() -- end)

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