Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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.

0
By "roblox server mode" you mean in the actual game? Or in studio play mode? Amiaa16 3227 — 5y

1 answer

Log in to vote
1
Answered by
Avigant 2374 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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.

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 XXXlawsonXXX 52 — 5y
Ad

Answer this question