GUI not appearing when touched part

So I’m trying to make a GUI appear when a player touches a part but it isn’t working.
Here’s my script,idk what’s wrong.

local Left = script.Parent.LeftDoor
local Touch = script.Parent.TouchOut
local Right = script.Parent.RightDoor
local GUI = game.StarterGui.Elevator.Frame

Touch.Touched:Connect(function(Hit)
	print(Hit.Name.." Touched!")
	local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)

	if Player then --Sanity checks for both a Player and a debounce cooldown
		print(Player.Name.." Touched!")
				GUI.Visible = true
			end
	end)
1 Like

You’re using StarterGui, which only replicates Guis to a player’s playerGui. You already have a Player instance set up, so just get their PlayerGui and enable the frame from there

local model = script.Parent
local Left = model.LeftDoor
local Touch = model.TouchOut
local Right = model.RightDoor

Touch.Touched:Connect(function(Hit)
	print(Hit.Name.." Touched!")
	local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)

	if Player then --Sanity checks for both a Player and a debounce cooldown
		print(Player.Name.." Touched!")
		local GUI = Player.PlayerGui.Elevator.Frame
		GUI.Visible = true
	end
end)

You probably need to make this into a localscript that verifies who touches the part if you have a close button for the frame or the frame’s visibility is changed from the client, because the server wont be able to detect changes to the frame if they’re done from the client

Edit: Nitpick but why does your comment mention a sanity check for both a Player check and a debounce when you only have the player check?

1 Like

Why not just use Remotes for this… Heres an example of how you would use one:

Server script inside part:

script.Parent.Touched:Connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid") then
		game.ReplicatedStorage.RemoteEvent:FireClient(game.Players:GetPlayerFromCharacter(Hit.Parent), true)
	end
end)

Create a new Remote inside ReplicatedStoage Event


Local script inside your gui:

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(Visible)
	script.Parent.Visible = Visible
end)

A remote event is not needed if the Touched event can be client sided with a check to make it only work for whoever touched. It can be converted to a localscript and placed somewher eit can run, such as StarterPlayerScripts and changed to this to give an example

local Players = game:GetService("Players")

local model = script.Parent
local Left = model.LeftDoor
local Touch = model.TouchOut
local Right = model.RightDoor

local player = Players.LocalPlayer

Touch.Touched:Connect(function(Hit)
	print(Hit.Name.." Touched!")
	local Player = Players:GetPlayerFromCharacter(Hit.Parent)

	if not Player or player ~= Player then 
		return
	end
	print(Player.Name.." Touched!")
	local GUI = Player.PlayerGui.Elevator.Frame
	GUI.Visible = true
end)

The check checks if a player wasn’t found or the player found is not the localplayer, if any of them happen, the event stops there until another part touches it

Do this:


local Left = script.Parent.LeftDoor
local Touch = script.Parent.TouchOut
local Right = script.Parent.RightDoor
local GUI = game.StarterGui.Elevator.Frame

Touch.Touched:Connect(function(Hit)
	print(Hit.Name.." Touched!")
	local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)

	if Player then --Sanity checks for both a Player and a debounce cooldown
		print(Player.Name.." Touched!")
				Player.PlayerGui.Elevator.Frame.Visible = true
			end
	end)

TY it worked but I want to ask something else
I’m trying to find the player who pressed the button on the GUI,how can I find him?
Here’s my script:

local player = game.Players:FindFirstChild(.Parent.Name)

Is it a GuiButton? If so, can’t you just use the LocalPlayer to check who clicked it?

If it isn’t a GuiButton, then please tell me what button do you mean

It is indeed a GUI button,a button inside a frame

Then the localplayer is all you need since localscripts are what is needed for gui buttons

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

It’s not working,
here’s my script for your information

SF.MouseButton1Down:Connect(function()

GUI.Visible = false

player.Character.HumanoidRootPart.CFrame = CFrame.new(close.Position.X,close.PositionY,close.PositionZ)

end)
local Player = game.Players.LocalPlayer
SF.MouseButton1Down:Connect(function()

GUI.Visible = false

player.Character.HumanoidRootPart.CFrame = CFrame.new(close.Position.X,close.PositionY,close.PositionZ)

end)

Did you forget to make a variable for the local player? Where is this script located? What is SF?

The script is located inside the frame
SF is a button called ‘Special Floor’
wdym variable for the local player?

Did you remember to make it a localscript?

You only provided this as a code sample, it doesn’t feature a variable for player

SF.MouseButton1Down:Connect(function()

GUI.Visible = false

player.Character.HumanoidRootPart.CFrame = CFrame.new(close.Position.X,close.PositionY,close.PositionZ)

end)

There’s a bit of vagueness because you didn’t specify what exactly isn’t work, the GUI thing or the movement? We may need to see the entire code, with the variables included.

And just be clear as well, are there any errors when attempting to use your code?

no there’s no error
yes it’s a local script

local F1 = script.Parent.Floor1

local F2 = script.Parent.Floor2

local F3 = script.Parent.Floor3

local SF = script.Parent.Special

local GF = script.Parent.GroundFloor

local GUI = game.Player.PlayerGui.Elevator.Frame

local close = game.Workspace.MiniGameElevator.ClosePart

F1.MouseButton1Down:Connect(function()

F1.BackgroundTransparency = 0.7

end)

F1.MouseButton1Down:Connect(function()

F1.BorderSizePixel = 3

end)

F1.MouseButton1Down:Connect(function()

F1.Text = "Your Current Floor"

end)

F1.MouseButton1Down:Connect(function()

F1.BackgroundColor3 = Color3.fromRGB(255,255,255)

end)

F2.MouseButton1Down:Connect(function()

F1.BackgroundTransparency = 0

end)

F2.MouseButton1Down:Connect(function()

F1.BorderSizePixel = 1

end)

F2.MouseButton1Down:Connect(function()

F1.Text = "Floor 1 -- Minigames"

end)

F2.MouseButton1Down:Connect(function()

F1.BackgroundColor3 = Color3.fromRGB(95, 255, 82)

end)

F3.MouseButton1Down:Connect(function()

F1.BackgroundTransparency = 0

end)

F3.MouseButton1Down:Connect(function()

F1.BorderSizePixel = 1

end)

F3.MouseButton1Down:Connect(function()

F1.Text = "Floor 1 -- Minigames"

end)

F3.MouseButton1Down:Connect(function()

F1.BackgroundColor3 = Color3.fromRGB(95, 255, 82)

end)

SF.MouseButton1Down:Connect(function()

F1.BackgroundTransparency = 0

end)

SF.MouseButton1Down:Connect(function()

F1.BorderSizePixel = 1

end)

SF.MouseButton1Down:Connect(function()

F1.Text = "Floor 1 -- Minigames"

end)

SF.MouseButton1Down:Connect(function()

F1.BackgroundColor3 = Color3.fromRGB(95, 255, 82)

end)

GF.MouseButton1Down:Connect(function()

F1.BackgroundTransparency = 0

end)

GF.MouseButton1Down:Connect(function()

F1.BorderSizePixel = 1

end)

GF.MouseButton1Down:Connect(function()

F1.Text = "Floor 1 -- Minigames"

end)

GF.MouseButton1Down:Connect(function()

F1.BackgroundColor3 = Color3.fromRGB(95, 255, 82)

end)

F2.MouseButton1Down:Connect(function()

F2.BackgroundTransparency = 0.7

end)

F2.MouseButton1Down:Connect(function()

F2.BorderSizePixel = 3

end)

F2.MouseButton1Down:Connect(function()

F2.Text = "Your Current Floor"

end)

F2.MouseButton1Down:Connect(function()

F2.BackgroundColor3 = Color3.fromRGB(255,255,255)

end)

F1.MouseButton1Down:Connect(function()

F2.BackgroundTransparency = 0

end)

F1.MouseButton1Down:Connect(function()

F2.BorderSizePixel = 1

end)

F1.MouseButton1Down:Connect(function()

F2.Text = "Floor 2 -- Other Games"

end)

F1.MouseButton1Down:Connect(function()

F2.BackgroundColor3 = Color3.fromRGB(255, 255, 116)

end)

F3.MouseButton1Down:Connect(function()

F2.BackgroundTransparency = 0

end)

F3.MouseButton1Down:Connect(function()

F2.BorderSizePixel = 1

end)

F3.MouseButton1Down:Connect(function()

F2.Text = "Floor 2 -- Other Games"

end)

F3.MouseButton1Down:Connect(function()

F2.BackgroundColor3 = Color3.fromRGB(255, 255, 116)

end)

SF.MouseButton1Down:Connect(function()

F2.BackgroundTransparency = 0

end)

SF.MouseButton1Down:Connect(function()

F2.BorderSizePixel = 1

end)

SF.MouseButton1Down:Connect(function()

F2.Text = "Floor 2 -- Other Games"

end)

SF.MouseButton1Down:Connect(function()

F2.BackgroundColor3 = Color3.fromRGB(255, 255, 116)

end)

GF.MouseButton1Down:Connect(function()

F2.BackgroundTransparency = 0

end)

GF.MouseButton1Down:Connect(function()

F2.BorderSizePixel = 1

end)

GF.MouseButton1Down:Connect(function()

F2.Text = "Floor 2 -- Other Games"

end)

GF.MouseButton1Down:Connect(function()

F2.BackgroundColor3 = Color3.fromRGB(255, 255, 116)

end)

F3.MouseButton1Down:Connect(function()

F3.BackgroundTransparency = 0.7

end)

F3.MouseButton1Down:Connect(function()

F3.BorderSizePixel = 3

end)

F3.MouseButton1Down:Connect(function()

F3.Text = "Your Current Floor"

end)

F3.MouseButton1Down:Connect(function()

F3.BackgroundColor3 = Color3.fromRGB(255,255,255)

end)

F1.MouseButton1Down:Connect(function()

F3.BackgroundTransparency = 0

end)

F1.MouseButton1Down:Connect(function()

F3.BorderSizePixel = 1

end)

F1.MouseButton1Down:Connect(function()

F3.Text = "Floor 3 -- Special Events"

end)

F1.MouseButton1Down:Connect(function()

F3.BackgroundColor3 = Color3.fromRGB(253, 131, 144)

end)

F2.MouseButton1Down:Connect(function()

F3.BackgroundTransparency = 0

end)

F2.MouseButton1Down:Connect(function()

F3.BorderSizePixel = 1

end)

F2.MouseButton1Down:Connect(function()

F3.Text = "Floor 3 -- Special Events"

end)

F2.MouseButton1Down:Connect(function()

F3.BackgroundColor3 = Color3.fromRGB(253, 131, 144)

end)

SF.MouseButton1Down:Connect(function()

F3.BackgroundTransparency = 0

end)

SF.MouseButton1Down:Connect(function()

F3.BorderSizePixel = 1

end)

SF.MouseButton1Down:Connect(function()

F3.Text = "Floor 3 -- Special Events"

end)

SF.MouseButton1Down:Connect(function()

F3.BackgroundColor3 = Color3.fromRGB(253, 131, 144)

end)

GF.MouseButton1Down:Connect(function()

F3.BackgroundTransparency = 0

end)

GF.MouseButton1Down:Connect(function()

F3.BorderSizePixel = 1

end)

GF.MouseButton1Down:Connect(function()

F3.Text = "Floor 3 -- Special Events"

end)

GF.MouseButton1Down:Connect(function()

F3.BackgroundColor3 = Color3.fromRGB(253, 131, 144)

end)

GF.MouseButton1Down:Connect(function()

GF.BackgroundTransparency = 0.7

end)

GF.MouseButton1Down:Connect(function()

GF.BorderSizePixel = 3

end)

GF.MouseButton1Down:Connect(function()

GF.Text = "Your Current Floor"

end)

GF.MouseButton1Down:Connect(function()

GF.BackgroundColor3 = Color3.fromRGB(255,255,255)

end)

F1.MouseButton1Down:Connect(function()

GF.BackgroundTransparency = 0

end)

F1.MouseButton1Down:Connect(function()

GF.BorderSizePixel = 1

end)

F1.MouseButton1Down:Connect(function()

GF.Text = "Ground Floor -- Hangout"

end)

F1.MouseButton1Down:Connect(function()

GF.BackgroundColor3 = Color3.fromRGB(255, 255, 225)

end)

F3.MouseButton1Down:Connect(function()

GF.BackgroundTransparency = 0

end)

F3.MouseButton1Down:Connect(function()

GF.BorderSizePixel = 1

end)

F3.MouseButton1Down:Connect(function()

GF.Text = "Ground Floor -- Hangout"

end)

F3.MouseButton1Down:Connect(function()

GF.BackgroundColor3 = Color3.fromRGB(255, 255, 225)

end)

SF.MouseButton1Down:Connect(function()

GF.BackgroundTransparency = 0

end)

SF.MouseButton1Down:Connect(function()

GF.BorderSizePixel = 1

end)

SF.MouseButton1Down:Connect(function()

GF.Text = "Ground Floor -- Hangout"

end)

SF.MouseButton1Down:Connect(function()

GF.BackgroundColor3 = Color3.fromRGB(255, 255, 225)

end)

F2.MouseButton1Down:Connect(function()

GF.BackgroundTransparency = 0

end)

F2.MouseButton1Down:Connect(function()

GF.BorderSizePixel = 1

end)

F2.MouseButton1Down:Connect(function()

GF.Text = "Ground Floor -- Hangout"

end)

F2.MouseButton1Down:Connect(function()

GF.BackgroundColor3 = Color3.fromRGB(255, 255, 225)

end)

SF.MouseButton1Down:Connect(function()

SF.BackgroundTransparency = 0.7

end)

SF.MouseButton1Down:Connect(function()

SF.BorderSizePixel = 3

end)

SF.MouseButton1Down:Connect(function()

SF.Text = "Your Current Floor"

end)

SF.MouseButton1Down:Connect(function()

SF.BackgroundColor3 = Color3.fromRGB(255,255,255)

end)

F1.MouseButton1Down:Connect(function()

SF.BackgroundTransparency = 0

end)

F1.MouseButton1Down:Connect(function()

SF.BorderSizePixel = 1

end)

F1.MouseButton1Down:Connect(function()

SF.Text = "???"

end)

F1.MouseButton1Down:Connect(function()

SF.BackgroundColor3 = Color3.fromRGB(108, 182, 192)

end)

F3.MouseButton1Down:Connect(function()

SF.BackgroundTransparency = 0

end)

F3.MouseButton1Down:Connect(function()

SF.BorderSizePixel = 1

end)

F3.MouseButton1Down:Connect(function()

SF.Text = "???"

end)

F3.MouseButton1Down:Connect(function()

SF.BackgroundColor3 = Color3.fromRGB(108, 182, 192)

end)

GF.MouseButton1Down:Connect(function()

SF.BackgroundTransparency = 0

end)

GF.MouseButton1Down:Connect(function()

SF.BorderSizePixel = 1

end)

GF.MouseButton1Down:Connect(function()

SF.Text = "???"

end)

GF.MouseButton1Down:Connect(function()

SF.BackgroundColor3 = Color3.fromRGB(108, 182, 192)

end)

F2.MouseButton1Down:Connect(function()

SF.BackgroundTransparency = 0

end)

F2.MouseButton1Down:Connect(function()

SF.BorderSizePixel = 1

end)

F2.MouseButton1Down:Connect(function()

SF.Text = "???"

end)

F2.MouseButton1Down:Connect(function()

SF.BackgroundColor3 = Color3.fromRGB(108, 182, 192)

end)

local Player = game.Players.LocalPlayer

SF.MouseButton1Down:Connect(function()

local player = game.Players.LocalPlayer

GUI.Visible = false

player.Character.HumanoidRootPart.CFrame = CFrame.new(close.Position.X,close.PositionY,close.PositionZ)

end)

Are you certain there’s no errors? This would’ve errored to by knowledge as there’s nothing called Player in the game.

Also, why is the player variable all the way down there? Put it with all your other variables and use its playergui for the GUI variable

Remove all instances of the game.Players.LocalPlayer variables and just put it behind the GUI variable

local player = game:GetService("Players").LocalPlayer
local GUI = player:WaitForChild("PlayerGui").Elevator.Frame

now the GUI disappears but doesn’t teleport me to the part

Try this for your SF MouseButton1Click function?

SF.MouseButton1Down:Connect(function()
	GUI.Visible = false
	local char = player.Character
	if not char then
		return
	end
	char:WaitForChild("HumanoidRootPart").CFrame = close.CFrame
end)

Is close a varaible belonging to a part or a model?

If this doesn;'t work then it could be that it isn’t a part or you may need a RemoteEvent

it worked! TY again for your help!

nvm,now if I teleport and return,the GUI disappears