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)„
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)
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)
print("Embed code like this, or with the </> button above.")
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)