Still have questions? Join our Discord server and get real time help.
Log in to vote

Is it possible to detect if a player already has a gui?

Asked by 6 months ago

So basically I made a part that on touched gives you a gui, but if you keep touching it you keep getting the gui. Is it possible to make it so it detects if you already have the gui. As from what I have seen the server even with knowing who the player is cannot see what gui they have

Add code DinozCreates 748 — 6mo
Add the code you used to someone can try to fix it. Crojix 6 — 6mo

1 answer

Log in to vote
Answered by 6 months ago

You can add some lines of code that verifies so that if the player already has the GUI the function won't fire

local players = game:GetService("Players")
local part = script.Parent
local GUI = part:WaitForChild("YourGUI") --//Pretend the GUI is located there

local function onTouched(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")

    if humanoid then --//Checks if it has a humanoid
        local playerName = hit.Parent.Name
        local sPlayer = players:WaitForChild(playerName)
        local playerGui = sPlayer:WaitForChild("PlayerGui")

        if playerGui:FindFirstChild("YourGUI") then return end --//Checks if the GUI is already at the player's screen, if true then return end

        local newGUI = GUI:Clone()
        newGUI.Parent = playerGui --//Clones the GUI to the player's screen


This is the first solution that came into my head, warn me if any error pops up


Answer this question