GUI open script! BASIC SCRIPTING!

Hello! So i have in my game a part that when touched it should open a GUI JUST for the player that touched it, but instead, it opens for everyone in the server. I have tried ALL of the scripts that are out there and none work!

Scripts i tryed:

„local player = game:GetService(“Players”).LocalPlayer
game.Workspace.OpenGuiPart.Touched:Connect(function(hit)
if hit and hit.Parent.Name == player.Name then
script.Parent.rom.MainFrame.Visible = true
end
end)„

Another one:

„local part = game.Workspace.OpenGuiPart

part.Touched:Connect(function()
script.Parent.rom.MainFrame.Visible = true
end)„

Thank you in advance!

1 Like

Please embed your code with three backticks before and after the code.

local player = game:GetService(“Players”).LocalPlayer
game.Workspace.OpenGuiPart.Touched:Connect(function(hit)
    if hit and hit.Parent.Name == player.Name then
        script.Parent.rom.MainFrame.Visible = true
    end
end)

im sorry but i dont know what any of that means :)))))

Is this a local script?
(ignore this pls)

The backtick is this character: `
You can find it by pressing the button underneath Esc in the top right of your keyboard (on most keyboards)

Kind of a complicated process.
STEP 1:
Create a RemoteEvent and place it in ReplicatedStorage. Name this RemoteEvent as ‘openGuiOnTouch’.
STEP 2:
Add a script inside the part:

local part = script.Parent
local remote = game.ReplicatedStorage.openGuiOnTouch

part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then remote:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
end)

STEP 3:
Add a LocalScript inside StarterGui. Put this code inside:

local remote = game.ReplicatedStorage.openGuiOnTouch
remote.OnClientEvent:Connect(function()
local gui = --the gui you want to open
gui.Visible = true
end)
3 Likes

like i did now?
im new to scripting

a local script inside the part or just a normal script?

A normal script inside the part and a LocalScript inside StarterGui

im trying this rn, wait a sec pls

1 Like

when u say „the gui you want to open„ how more exactly would that be like?
like script.parent.example.exampleframe.visible = true?

Yes.

This text will be blurred

there should i replace it with the name of the part? like our part?

No, just keep that script as it is.

image
the gui wont even work anymore
like it wont open

Check the output to see any errors.
Can you also show me a screenshot of the explorer screen, where your gui is?

It opens now but still for everyone

image

It worked now, thank you so much!

1 Like
print("Embed code like this, or with the </> button above.")

image

Your scripts would look like this:

-- LocalScript
local player = game.Players.LocalPlayer
game.Workspace.OpenGuiPart.Touched:Connect(function(hit)
	if hit and hit.Parent.Name == player.Name then
		script.Parent.rom.MainFrame.Visible = true
	end
end)
-- Most likely the issue
local part = game.Workspace.OpenGuiPart

part.Touched:Connect(function()
	script.Parent.rom.MainFrame.Visible = true
end)