Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Open a GUI While standing on part?

Hi! I am attempting to make a working walk-in-wardrobe, where when you walk in, and touch the part, it will open the GUI, Then when you walk out, it detects that, and closes the gui. So the GUI is open on a while loop, Similar to this psuedo code:

part = Script.Parent
gui = player.PlayerGui.ClothesGui.MainFrame
while player touching part:
gui.visible = True
else
gui.visible = False

Any help appreciated, Many Thanks, Mineblocks47

4 comments

0

If you don't have experience with Lua then there's no point in helping you giving you free code. Learn by starting at developer.roblox.com

0

lol

0

Use Touched and TouchEnded events

0

GUI wont really work with touching a brick that easily.. you need to use Remote Events.

2 answers

Hello! First: you need to insert Script in the part and place this:

local RemoteEvent = Instance.new("RemoteEvent")
RemoteEvent.Parent = game.Workspace
RemoteEvent.Name = "ClothesEvent"

function onTouched(hit)
    local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
    RemoteEvent:FireClient(Player)
end

script.Parent.Touched:Connect(onTouched)

Second: Insert LocalScript in MainFrame and place this:

game.Workspace:WaitForChild("ClothesEvent")
local debounce = false

game.Workspace.ClothesEvent.OnClientEvent:Connect(function ()
    if debounce == false then
        script.Parent.Visible = true
        debounce = true
    end
end)

Also if you want to close the shop you should to insert TextButton in MainFrame and insert LocalScript and place this:

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.Visible = false
end)

I hope that helps you. Good luck.

If you want a TweenPosition, then I got one for you. First insert a normal Script inside of the part you want to touch. Then put the ScreenGUI inside of the script and name it for example "Shop" in your script. (If you want to change the name of your ScreenGUI, then also change it in the script that ahs the name Shop) And then once you put it all in it should look like this: Part > Script > Shop

Here's the script:

local Delay = 1 -- Time it takes to scroll down / up

function onTouch(hit)

    if game.Players:FindFirstChild(hit.Parent.Name) then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if not player.PlayerGui:FindFirstChild("Shop") then
            local gui = script.Shop:Clone()
            gui.Parent = player.PlayerGui

            gui.Frame:TweenPosition(UDim2.new(.5,0,.5,0),"Out","Quad",Delay,true)
            repeat wait() until (player.Character.HumanoidRootPart.Position - script.Parent.Position).magnitude > 5

            gui.Frame:TweenPosition(UDim2.new(.5,0,-.5,0),"Out","Quad",Delay,true)
            wait(Delay)
            gui:Remove()
        end
    end

end

script.Parent.Touched:Connect(onTouch)

This discussion is preserved as it was. New answers, comments, and votes are closed.