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

"Play" mode unable to find the player's Gui?

As with a lot of other posts, this problem is not in test mode but rather in the Roblox "Play" mode. I have a server script that will detect when a player is inside the part "ENTERSHOP" and will make the player's shop GUI visible. When the script detects a player in the Roblox server mode, it is seemingly unable to find the ScreenGui "Gui" as a child of PlayerGui and throws an "Infinite yield possible" error relating to line 10

local part = script.Parent
local debounce = false

part.Touched:connect(function(hit)
	if debounce == false then
		debounce = true
		if hit.Parent:FindFirstChild('Humanoid') then
			local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
			if plr then
				if plr.PlayerGui:WaitForChild("Gui").Shop.Visible ~= true then
					plr.PlayerGui:WaitForChild("Gui").Shop.Visible = true
				end
			end
		end
		debounce = false
	end
end)

part.TouchEnded:connect(function(hit)
	if debounce == false then
		debounce = true
		if hit.Parent:FindFirstChild('Humanoid') then
			local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
			if plr then
				if plr.PlayerGui:WaitForChild("Gui").Shop.Visible ~= false then
					plr.PlayerGui:WaitForChild("Gui").Shop.Visible = false
				end
			end
		end
		debounce = false
	end
end)

I know that the scripts are a little sloppy but I plan on cleaning it up after the bugs are fixed.

1 comment

0

By "roblox server mode" you mean in the actual game? Or in studio play mode?

1 answer

✓ Accepted answer

In Studio's Play Solo mode (when you hit Play), there is no separation of client and server. This means that the client and server can do things in it that they really shouldn't be able to. Use Test Server mode to simulate a live server. Check that your scripts are in the correct containers, and that the server is not trying to do something client-only, and vice versa.

In this specific case, it's important to remember that when the client parents something to Player.PlayerGui, it is not replicated. Instead, you should listen to BasePart.Touched client-side, since all you're doing is adding latency by doing this server-side.

Also, RBXScriptSignal:connect() is deprecated, prefer RBXScriptSignal:Connect() instead.

Also, no need to check for a humanoid, just call game.Players:GetPlayerFromCharacter() as you're doing without the humanoid check.

1 comment

0

Thanks, this will solve tons of problems in the future. My 10:00 pm tired Brain must have assumed to do it server sided because filteringenabled

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