How do I make a part open a UI

I have a circular part by my rebirth shop.


How do I make the part open a UI and when they step of the part, it closes.

1 Like

or

or

1 Like
-- add this in a script under the part
local part = script.Parent
local Players = game:GetService("Players")
part.Touched:Connect(function(hit)
    if hit.Parent:WaitForChild("Humanoid") then
    local player = Players:GetPlayerFromCharacter(hit.Parent)
    player.PlayerGui.Frame.Visible = true -- change frame with the gui
    end
end)
-- Also, I recommend adding a red button (or a button to exit the gui) because this script wont close it.
2 Likes

He can use some kind of loop to detect once he comes out of the shop area.

1 Like

Maybe add a part so when the player touches it, the GUI closes.

-- add a script to the parts
local exitPart = script.Parent -- or change the name
local Players = game:GetService("Players")
exitPart.Touched:Connect(function(hit)
    if hit.Parent:WaitForChild("Humanoid") then
    local player = Players:GetPlayerFromCharacter(hit.Parent)
    player.PlayerGui.Frame.Visible = false
    end
end)
2 Likes

This can be done via server to client communication.
a script will see if the part is touched, then gets the player from the character that touched it with:
game.Players.GetPlayerFromCharacter ( Instance character ).

And then using that player as a target to fire a remote event: FireClient ( Instance target player , Tuple arguments ).

Then there will be a local script that will listen if the Remote has been client fired: RemoteEvent. OnClientEvent ( Tuple arguments ), and when this event happens, you open up the GUI with the script.

More info:

Note: Stepping of the part event can be done by listening to the event: Part. TouchEnded ( Instance otherPart ).

@wc3u has made a great script example.

Use a .Touched event like @GoteeSign suggested to open the gui, then a .TouchEnded event to close the gui. Also, instead of using the original part, create another invisible, CanCollide false cylinder which extends a few studs upwards and use the Touched events on that (this is so when the player jumps, the shop doesn’t close)

local Part = script.Parent

Part.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        local gui = player.PlayerGui.Frame

        if gui.Visible == false then -- only open the gui when required
            gui.Visible = true
        end
    end
end)

Part.TouchEnded:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        local gui = player.PlayerGui.Frame

        if gui.Visible == true then -- only close the gui when required
            gui.Visible = false
        end
    end
end)
5 Likes

Try using this video. Maybe it’ll help you a bit.

You could use TouchEnded to detect when to close the gui.

2 Likes