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

For loop is looping in an incorrect order?

I have a server script and a local script. The Server script reacts to a fired server event then loops through a folder in ReplicatedStorage with 16 string values called Claim_A, Claim_B, etc. If the value is empty, the player's name will be entered in the value and the loop will break and will fire a remote event back at all clients.

Claims

The local script is a for loop that will create the function where if one of the values change, it will find the frame inside ClaimFrame with the same name as itself.

ClaimFrame

The problem is that it starts on the wrong frame.

server script

Claim.OnServerEvent:Connect(function(Player)
	print("we got it boys")
	for i,v in pairs(Claims:GetChildren())do
		print(v)
		if v.Value == "" then--if its nothing
			v.Value = Player.Name
			print(Player.Name,"is",Claims[v.Name])
			break
		end
	end
end)

local script

for i,v in pairs(Claims:GetChildren()) do
	v.Changed:Connect(function()
		if v.Value ~= "" then --if its not nothing
			ClaimFrame[v.Name].Username.Text = v.Value
			ClaimFrame[v.Name].Visible = true
			game.SoundService.Bonk:Play()
		end
	end)
end

1 answer

Looping through a model or object is not guaranteed for it to go in order because of how the explorer it setup. One method is using a table and iterating through it.

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