Pretty self explanatory, I touch a part, GUI opens, I close it, touch part again, GUI does not open back up
Local script 1:
local TouchPart = game.Workspace:WaitForChild("RuneCraftPart") -- Change Part to whatever your part is called which a player will need to touch
local gui = script.Parent
TouchPart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent == game.Players.LocalPlayer.Character then
gui.Visible = true
gui:TweenSize(UDim2.new(1,0,1,0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, .2, true)
print("Gui opened")
end
end)
Localscript 2
local button = script.Parent
local frame = script.Parent.Parent.Parent
button.MouseButton1Click:Connect(function()
frame:TweenSize(UDim2.new(0.1,0,0.1,0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, .2, true)
task.wait(0.2)
frame.Visible = false
end)
You’re using a Touched event in a LocalScript to open the GUI. However, LocalScripts run on the client side, which means they might not be the best choice for handling GUI interactions. Instead, consider using a server-side solution.
local TouchPart = game.Workspace:WaitForChild("RuneCraftPart")
local gui = script.Parent
TouchPart.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
local frame2 = player.PlayerGui:FindFirstChild("BoothGui"):FindFirstChild("Frame2")
if frame2 then
frame2.Visible = not frame2.Visible
print("GUI toggled")
end
end
end)
If you encounter any further issues, feel free to ask for help!
It’s probably easier to put this into a single script.
Replace Script1 with this and delete Script2
local TouchPart = game.Workspace:WaitForChild("RuneCraftPart") -- Change Part to whatever your part is called which a player will need to touch
local gui = script.Parent
local button = gui:WaitForChild("TextButton") -- Change this to the Path/Name of your button
button.MouseButton1Click:Connect(function()
gui:TweenSize(UDim2.new(0.1,0,0.1,0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, .2, true, function() gui.Visible = false end)
end)
TouchPart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent == game.Players.LocalPlayer.Character then
gui.Visible = true
gui:TweenSize(UDim2.new(1,0,1,0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, .2, true)
print("Gui opened")
end
end)
I’ve tested the above script and it works as intended.
I also made one slight change to the buttonClick code where I used the callback in TweenSize to close the Gui instead of using task.wait(2) and then closing it.
callback is simply a function the TweenSize runs after the tween has completed.