Why won't this work?

Might be simple but I can’t seem to get this. It is supposed to make ui visible when a part is touched. It’s in a local script inside the part being touched. ` local Popup = game.Players.LocalPlayer.PlayerGui.VoucherExchange.etoopen

function onTouch(hit)
if Popup.Visible == false then
Popup.Visible = true
end
end

script.Parent.Touched:connect(onTouch) `

Local Scripts will not run in Workspace.

You can move the script to the GUI.

local Part = game.Workspace:WaitForChild("Part")

1 Like

How exactly would i detect if the part is touched?

You use a ServerScript to detect .Touch, then you will use a RemoteEvent to manipulate the player’s Gui.

Put script in part being touched then when part touched, open the ui

local Part = script.Parent

Part.Touched:Connect(function(hit)
	local Humnoid = hit.Parent:FindFirstChild("Humanoid")
	if Humnoid then
		local plr = game.Players:GetPlayerFromCharacter(Humnoid.Parent)
		plr.PlayerGui.VoucherExchange.etoopen.Visible = true
	end
end)

Though I would suggest you use a proximity prompt or ClickDetector to open the gui rather than .touch

You can just have a LocalScript inside the GUI that listens for a part in workspace to be touched.

local WS = game:GetService("Workspace")
local Part = WS:WaitForChild("Part")

function onTouch(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if hit.Parent.Name == Player.Name then
			if Popup.Visible == false then
				Popup.Visible = true
			end
		end
	end
end

Part.Touched:connect(onTouch)