Issue changing values

essentially im trying to make a leaderboard whereby players names are under a text label, either pirates or marines, everything works however when I try to change the person faction it doesn’t update to the leaderboard. i tried making it so that an event fires from the server whenever the players faction changes and then it updates it to all clients. the issue is that the layout value doesn’t change to 4, it stays at 2. how would I fix this?

local plr = game:GetService("Players").LocalPlayer
local rs = game:GetService("ReplicatedStorage")
local event = rs.RemoteEvents.FactionChanged
function update() 
	
	for i, v in pairs(script.Parent.PlayersFrame:GetChildren()) do 
		if v:IsA("TextLabel") and v.Name ~= "PirateList"  and v.Name ~= "MarineList" then 
			v:Destroy()
		end
	end
	--

	for i, player in pairs(game.Players:GetChildren()) do 
		local leaderbaord = script.Parent
		local PlayerListFrame = leaderbaord.PlayersFrame
		local playertextclone = rs.Gui:WaitForChild("PlayerName"):Clone()
		if plr.leaderstats.Faction.Value == "Pirate" or "None" then
			playertextclone.Parent = PlayerListFrame
			playertextclone.LayoutOrder = 2
			playertextclone.Text = player.Name
			playertextclone.Visible = true
			
		elseif plr.leaderstats.Faction.Value == "Marine" then
			playertextclone.Parent = PlayerListFrame
			playertextclone.LayoutOrder = 4
			playertextclone.Text = player.Name
			playertextclone.Visible = true
		end
	end
end

update()

game.Players.PlayerAdded:Connect(function()
	update()
end)

game.Players.PlayerRemoving:Connect(function() 
	wait(2) 
	update() 
end)

event.OnClientEvent:Connect(function()
	print("FactionChangerWorks")
	update()
end)



2 Likes

Why didn’t you directly communicate from the client to the server for the change of the team and change of value? I think that’s a better way to do it.

1 Like

Im not sure what you mean, do you mean that I should change the layout order in the serverscript?

1 Like

Is the script you’ve provided a serverscript?
Also important question: How does the player switch teams? Through a gui?

1 Like
  1. its a local script
  2. basically the faction value is part of the players stats, basically once the faction value changes, using a remote event it sends a signal to a serverscript to then fire another event to all clients and thus updating the leaderboard. (also the switching faction stuff all works, even the function to update the leaderboard works but the only issue is changing the layout value
1 Like