How to make a gui appear when a player touch a part?

Can someone help me fix my code? When the player touches the part, the GUI image transparency is set to zero

You are only setting the visibility in startergui, you have to do it through the players “PlayerGui”.

There are two different ways you could handle this.

  1. From the server
  2. From the client

Server:

local Players = game:GetService("Players")
local Part = script.Parent

Part.Touched:Connect(function(hit)
    local Character = hit.Parent

    if Character:IsA("Model") and Players:GetPlayerFromCharacter(Character) then -- Checks If The Character Is A Model, and If The Model Is A Character Of A Player.
        local Player = Players:GetPlayerFromCharacter(Character)
        local PlayerGui = Player:WaitForChild("PlayerGui") -- Gets The Players GUI
        -- Make Gui Visible
        local Gui = PlayerGui:WaitForChild("PopUp")
        Gui.Frame.Visible = true -- Not needed if your frames property "Visible" is already set to true
        Gui.Frame.ImageLabel.ImageTransparency = 0
    end
end)

Client:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer

local Part = workspace.Part -- The Part That Has The Touched Event

local Gui = script.Parent -- The GUI Object, that this local script is inside of.
local Frame = Gui.Frame
local ImageLabel = Frame.ImageLabel

Part.Touched:Connect(function(hit)
    local Character = hit.Parent
    if Character:IsA("Model") and Players:GetPlayerFromCharacter(Character) then -- Checks if the Character is a model, and is a character of a player.
        local plr = Players:GetPlayerFromCharacter(Character)
        if plr == Player then -- Checks if the touched player is the client.
            Frame.Visible = true -- Not needed if your frames property "Visible" is already set to true
            ImageLabel.ImageTransparency = 0
        end
    end
end)

You’re simply changing the value for the UI in the StarterGui folder

Every player has their own version of said folder (afaik)

First, You need to get the LocalPlayer :

local Player = game.Players.LocalPlayer

Next, You reference the Players PlayerGui :

local PlayerGUI = Player.PlayerGui or Player:FindFirstChild("PlayerGui") -- the OR exists because simply stating Player.PlayerGui might fail at times

Finally, I believe, you can change the transparency with :

PlayerGui.Popup.Frame.ImageLabel.ImageTransparency = 0

(Simply treat ‘PlayerGui’ as the StarterGui folder when it comes to referencing things inside it)

Hope this helped!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.