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

How would I input the KO's for each player in each slot?

I've tried scripting it to make sure it takes the leaderboards KO's and separates it for each player to display it on a surfacegui But instead it takes the same KO's for each player and puts it in the slots and their the same as one of the players What I want is basically the KO's from the lb to match correctly but separately for each player but it takes one of the players KO's and does it for both players making them the same KO's Any help?

game.Players.PlayerAdded:connect(function(player)
		if player.TeamColor==game.Teams.Fighting.TeamColor then
			while wait(2) do
workspace:FindFirstChild("_Screen"):FindFirstChild("ScreenTwo"):FindFirstChild("Display"):FindFirstChild("plr_2"):FindFirstChild("plr_Score").Text=player:FindFirstChild("leaderstats"):FindFirstChild("KOs").Value
workspace:FindFirstChild("_Screen"):FindFirstChild("Screen"):FindFirstChild("Display"):FindFirstChild("plr_1"):FindFirstChild("plr_Score").Text=player:FindFirstChild("leaderstats"):FindFirstChild("KOs").Value
workspace:FindFirstChild("_Screen"):FindFirstChild("Screen"):FindFirstChild("Display"):FindFirstChild("plr_2"):FindFirstChild("plr_Score").Text=player:FindFirstChild("leaderstats"):FindFirstChild("KOs").Value
workspace:FindFirstChild("_Screen"):FindFirstChild("ScreenTwo"):FindFirstChild("Display"):FindFirstChild("plr_1"):FindFirstChild("plr_Score").Text=player:FindFirstChild("leaderstats"):FindFirstChild("KOs").Value		
		end
	end
end)
				
				
		

1 answer

A few notes:

  • You use FindFirstChild a lot, but you either want WaitForChild or simply use a normal access, like workspace._Screen.ScreenTwo (etc). FindFirstChild is only useful if you deal with the possibility that it might return nil.
  • You either need a player slot for every possible player, or else you need to dynamically add player slots
  • Instead of calling wait(2), you might want to set it up so that you use a Changed event and only update the values when one of the KO numbers change. ex, say you only had 1 display for one player; your script could then be:
game.Players.PlayerAdded:connect(function(player)
	player:WaitForChild("leaderstats"):WaitForChild("KOs").Changed:connect(function(value)
		workspace._Screen.Screen.Display.plr_1.plr_Score.Text = value
	end)
end)

An alternative that might work:

local screen = workspace._Screen
local maxPlayers = 8
local i, kos
while true do
	wait(2)
	i = 0
	for _, player in ipairs(game.Players:GetPlayers()) do
		kos = player:FindFirstChild("leaderstats")
		kos = kos and kos:FindFirstChild("KOs")
		if kos and player.TeamColor==game.Teams.Fighting.TeamColor then
			i = i + 1
			--assign 'player.Name' to screen here; I don't know what label(s) you have for that purpose, but it might be something like:
			screen.Screen.Display["plr_" .. i].plr_Name.Text = player.Name
			screen.Screen.Display["plr_" .. i].plr_Score.Text = kos.Value
		end
	end
	for j = i + 1, maxPlayers do --reset unused slots
		screen.Screen.Display["plr_" .. i].plr_Name.Text = ""
		screen.Screen.Display["plr_" .. i].plr_Score.Text = 0
	end
end

The idea with this script is to update the "screen" for all players simultaneously. It would probably need a bit of editing for you to use it (ex changing values/what's accessed depending on your situation).

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