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

Unsure of the issue between a silent PlayerUI Reader and a ServerScript unresponsive? [Big Question]

I'm writing a quick playerRequirementCheck loop for a Round Based Game. The issue here is that it's not actually checking for the number of Players again after the first "failure", or so what I'm reading from Debug Statements; prints. Everything doesn't seem to work, only in Play Solo does things function properly, following all the requested statements in Output

[As I say "PlayerUI Reader", I'm referring to the ol' Status Bar, a StringValue called 'Currentinfo' withholding each instructed String passed by the 'CoreScript', picked up by the 'Reader' LocalScript inside of the Players UI, updating the TextLable to the Currentinfo's value.]

Heres the playerCheck loop

while wait() do
			
			print("PlrCheck?")
			
			AllPlayers = {}
			for _,Player in pairs(game:GetService("Players"):GetPlayers()) do
				if Player and Player.Character then
					if Player.Character.Humanoid then
						table.insert(AllPlayers, Player)
					end
				end
			end
			if #AllPlayers < RequiredPlayerCount then
				if not InsufficientPlayers then
					Script.SetString(Currentinfo, "Waiting for "..RequiredPlayerCount.." players..."); InsufficientPlayers = true
					print("PlrCheck_below")
				elseif #AllPlayers >= RequiredPlayerCount then
					if InsufficientPlayers then
						Script.SetString(Currentinfo, "Sufficient Players!"); wait(1); InsufficientPlayers = false
						print("PlrCheck_enough;push")
					end
					break
				end
			end
		
		end;

Heres the function used to Shortcut the Currentinfo Instance.

Script = {
		
		
		SetString = function(SetInstance, String)
			if not SetInstance then
				error("Unable to Set String for instance '"..SetInstance.."' (Propterty doesn't exist).")
			end
			SetInstance.Value = String, print(Currentinfo.Value, String, SetInstance)
		end;
		
	};

This is the Reader

local Currentinfo = game:GetService("ReplicatedStorage"):WaitForChild("Other").Currentinfo
local Player = game:GetService("Players").LocalPlayer; local Header = Player:WaitForChild("PlayerGui").BaseGuis.BaseHeader.Header 
local function SetHeader()
	print("SetHeaderRunning?")
    if Currentinfo then print("CIRemotePresent[SetHeaderCheck]")
        local Header = Player:WaitForChild("PlayerGui").BaseGuis.BaseHeader.Header; if Header then print("HeaderPresent") end
        Header.Text = Currentinfo.Value; if Header.Text == Currentinfo.Value then print('"'..Currentinfo.Value..'"_UpdatedHdr') end
    end;
end;
Currentinfo:GetPropertyChangedSignal("Value"):Connect(SetHeader)

This is the Output for all Statements, any other called aren't there

PlrCheck? Waiting for 3 players... Currentinfo PlrCheck_below PlrCheck? (x[inf#]) - repeated The Header is a GUI placed at the top of the Screen, it rests at "Default", the Reader isn't responding, nor functioning. It should rest at "Waiting for 3 players..."

If I am stupid enough to not see anything, please help me. Thanks

1 answer

✓ Accepted answer

"The issue here is that it's not actually checking for the number of Players again after the first "failure""

Actually, you told it not to by setting InsufficientPlayers = true and only acting if not InsufficientPlayers then (which is fine, but leads to the lack of output). Also, if you increase the number of players, your if layout creates an impossibility - it can only check if there are enough players if there aren't enough players (if #AllPlayers < RequiredPlayerCount then has to be true before elseif #AllPlayers >= RequiredPlayerCount then can be checked) - to fix that, end the nested if first (so that the elseif belongs to the first if, not the nested one).

In your last script you should call SetHeader() at the very end; the connection you make won't trigger until the next change occurs.

3 comments

0

Is that consistent throughout every connection, or only after the first call? I'm knew to GetPropertyChangeSignal(), I also thought switching from being unnested to nested would break it. I don't remember exactly why i changed it

0

Should I untie the if statements from the Insufficient variable all together too?

0

Not entirely sure what you mean in your 1st comment, but events never fire the moment you connect them, which is why you need to call the SetHeader() function yourself so that it isn't showing the default text. As for your 'if' statements involving 'insufficientPlayers', those are fine - they ensure your script only does those actions when they need to be done, instead of constantly.

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