I am trying to make it so that when you rebirth the points required to do so increase based on the number of rebirths you have and the text on a GUI changes to that amount. For whatever reason, the GUI text doesn’t change at all and I can’t figure out why.
local p = 0
local plr = game.Players.LocalPlayer
local reb = plr.leaderstats.Rebirths
local txt = script.Parent
game.Players.PlayerAdded:Connect(function(plr)
if reb.Value < 1 then
p = reb.Value * 1000/2
txt.Text = "Rebirth:".. tostring(p)
end
end)
reb.Changed:Connect(function()
if reb.Value < 1 then
p = reb.Value * 1000/2
txt.Text = "Rebirth:".. tostring(p)
end
end)
local p = 0
game.Players.PlayerAdded:Connect(function(Player)
local reb = Player.leaderstats.Rebirths
reb.Changed:Connect(function()
if reb.Value < 1 then
p = reb.Value * 1000/2
game.ReplicatedStorage.RemoteEvent:FireClient(Player,p)
end
end)
end)
game.Players.PlayerAdded:Connect(function(plr)
This event only runs on the server ,meaning - a normal script, not on local scripts.
You can either fire a remote to update the text whenever the rebirth’s value changes [from the server].
--Server
local p = 0
game.Players.PlayerAdded:Connect(function(Player)
local reb = Player.leaderstats.Rebirths
reb.Changed:Connect(function()
if reb.Value < 1 then
p = reb.Value * 1000/2
game.ReplicatedStorage.RemoteEvent:FireClient(Player,p)
end
end)
end)
--Client
local RS = game:GetService("ReplicatedStorage")
local Remote = RS:WaitForChild("RemoteEvent")
Remote.OnClientEvent:Connect(function(Player,Rebirths)
script.Parent.TextLabel.Text = "Rebirths: "..Rebirths
end)
or:
local Player = game.Players.LocalPlayer
local p = 0
Player:WaitForChild("leaderstats").Rebirths.Changed:Connect(function()
if Player:WaitForChild("leaderstats").Rebirths.Value > 1 then
p = Player:WaitForChild("leaderstats").Rebirths.Value * 1000/2
script.Parent.TextLabel.Text = "Rebirths: "..p
end
end)
PlayerAdded does work clientside as well, though it used to not have that functionality in the past.
What I think may be the issue here is that you are testing this in play solo mode possibly? PlayerAdded will not trigger or behave like normal in play solo mode. You should also update the text before those connections.
local p = 0
local plr = game.Players.LocalPlayer
local reb = plr.leaderstats.Rebirths
local txt = script.Parent
function UpdateText()
if reb.Value < 1 then
p = reb.Value * 1000/2
txt.Text = "Rebirth: "..p
end
end
UpdateText()
game.Players.PlayerAdded:Connect(function(plr)
UpdateText()
end)
reb.Changed:Connect(function()
UpdateText()
end)
If rebirth is 0, the text displayed would be “Rebirth: 0”? If it’s -1, it would display “Rebirth: -500”, if rebirth is 1 or above the text wouldn’t change. Could it be possible you meant to use a ≥ symbol instead of < symbol? I’m not exactly sure what the if reb.Value < 1 then condition does contextually speaking.
In the case of LocalScripts, the player joins, is given its character and scripts, and then the script connects to the PlayerAdded event. It will still fire when other players join, it just won’t be able to see their own join event.