Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Local Server not executing scripts for all players, my fault or Roblox's?

For some reason when I start a Local Server with 4 players, the scripts only seem to work for Player1, Player2, and Player3. Is this an error on my end or on Roblox's end?

I have a custom leaderboard set up and working for Player1, 2, and 3 but it doesn't show any names for Player4.

Below are both scripts that could've caused this somehow.

Server Side

game.ReplicatedStorage.REPlayerJoining.OnServerEvent:Connect(function(playerJ)
	if playerJ.PHBS then else
		local playerfolder = Instance.new("Folder", playerJ)
		playerfolder.Name = "Statistics"
		--
		local timeplayed = Instance.new("NumberValue", playerJ)
		timeplayed.Name = "TimePlayed"
		local timeplayedscript = script.TimePlayedScript:Clone()
		timeplayedscript.Parent = timeplayed
		timeplayedscript.Disabled = false
		--
		local phbs = Instance.new("IntValue")
		phbs.Name = "PHBS"
		phbs.Parent = playerJ
	end
end)

Client Side

game.Players.PlayerAdded:Connect(function(playerJ)
	for i,v in pairs(playersframe:GetChildren()) do
		if v:IsA("TextButton") then
			v:Destroy()
		end
	end
	for i,v in pairs(game.Players:GetChildren()) do
        local ptclone = game.ReplicatedStorage.PlayerTemplate:Clone()
        ptclone.Name = v.Name
        ptclone.PlayerName.Text = v.Name
		ptclone.Parent = playersframe
	end
	--
	game.ReplicatedStorage.REPlayerJoining:FireServer()
end)

game.Players.PlayerRemoving:Connect(function(playerL)
	playersframe[playerL.Name]:Destroy()
	--
	game.ReplicatedStorage.REPlayerLeaving:FireServer()
end)

1 comment

0

There is little to nothing we can do to help without any scripts. Please post the code so we can assist you further.

1 answer

Player 1, 2, and 3 would need to rejoin for their names because you only used a PlayerAdded event to add names and never include names of players actually there without someone else joining. You can easily loop through all the players to add their names like

for _, plr in pairs(game.Players:GetPlayers()) do
        local ptclone = game.ReplicatedStorage.PlayerTemplate:Clone()
        ptclone.Name = v.Name
        ptclone.PlayerName.Text = v.Name
        ptclone.Parent = playersframe
end

and your fixed function for PlayerAdded

game.Players.PlayerAdded:Connect(function(playerJ)
        --just adding frames would be fine enough instead of redoing it completely 
        local ptclone = game.ReplicatedStorage.PlayerTemplate:Clone()
        ptclone.Name = playerJ.Name
        ptclone.PlayerName.Text = playerJ.Name
        ptclone.Parent = playersframe

         --handle playeradded events on the server for leaderboard!
end)

Hope this helps!

This discussion is preserved as it was. New answers, comments, and votes are closed.