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

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

Asked by 5 years 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

0
Add code DinozCreates 1070 — 5y
0
Add the code you used to someone can try to fix it. DuckOffender 6 — 5y

1 answer

Log in to vote
0
Answered by 5 years 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
    end
end

part.Touched:Connect(onTouched)

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

Ad

Answer this question