Setting TextLabel Text

local script

local Player = game.Players.LocalPlayer
Player.PlayerGui.StatLabels.ClickStatFrame.ClickStatLabel.Text = Player:WaitForChild("leaderstats"):WaitForChild("Clicks").Value
Player.PlayerGui.StatLabels.RebirthStatFrame.RebirthStatLabel.Text = Player:WaitForChild("leaderstats"):WaitForChild("Rebirths").Value
Player.leaderstats.Clicks:GetPropertyChangedSignal("Value"):Connect(function()
	Player.PlayerGui.StatLabels.ClickStatFrame.ClickStatLabel.Text = Player.leaderstats.Clicks.Value
end)
Player.leaderstats.Rebirths:GetPropertyChangedSignal("Value"):Connect(function()
	Player.PlayerGui.StatLabels.RebirthStatFrame.RebirthStatLabel.Text = Player.leaderstats.Rebirths.Value
end)

Script

local DataStoreService = game:GetService("DataStoreService")
local ClicksStore = DataStoreService:GetDataStore("Clicks")
local RebirthsStore = DataStoreService:GetDataStore("Rebirths")
game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder",player)
	leaderstats.Name = "leaderstats"
	
	local Clicks = Instance.new("IntValue",leaderstats)
	Clicks.Name = "Clicks"
	if ClicksStore:GetAsync(player.UserId) == nil then
		Clicks.Value = 500
	else 
		Clicks.Value = ClicksStore:GetAsync(player.UserId)
	end
	
	local Rebirths = Instance.new("IntValue",leaderstats)
	Rebirths.Name = "Rebirths"
	if RebirthsStore:GetAsync(player.UserId) == nil then
		Rebirths.Value = 0
	else
		Rebirths.Value = RebirthsStore:GetAsync(player.UserId)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	ClicksStore:SetAsync(player.UserId,player.leaderstats.Clicks.Value)
	RebirthsStore:SetAsync(player.UserId,player.leaderstats.Rebirths.Value)
end)

When I join, the RebirthLabel is working fine, but the ClickLabel says 0 until I click the screen(Changing the property Value(GetPropertyChangedSignal)). Ex: Lets say my Clicks value is 2000, when i first join, it says 0, but when i first click it changes to 2001.

1 Like

Maybe place the line 2 and 3 in local script to the last line of the local script (not inside of a function by the way)

1 Like

Now rebirths isnt working.
[14:47:45.315 - Rebirths is not a valid member of Folder]

1 Like

Can you also include which line that includes that error

1 Like

You need to have a remote event that fires the amount when the player joins with the amount.

local Rebirths = Instance.new("IntValue",leaderstats)
	Rebirths.Name = "Rebirths"
	if RebirthsStore:GetAsync(player.UserId) == nil then
		Rebirths.Value = 0
	else
		Rebirths.Value = RebirthsStore:GetAsync(player.UserId)
	end

local function RebirthUpdate(amount)
game.ReplicatedStore.RemoteEvent:FireClient(amount)
end

RebirthUpdate(Rebirth.Value)

You’ll need to do OnClientEvent in the local script and set the amount to amount