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
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)