Why won't the GUI show if a player is touching a part?

I am making it so if a player touches a part, the shop gui shows, but only for them. So far it doesn’t work with no errors, and I am using a local script.

function Touch(hit)
	local player = game.Players.LocalPlayer
    if player then
	game.StarterGui.ShopGui.Frame.Visible = true
end
script.Parent.Touched:connect(Touch)

instead of using starter Gui, you need to use player GUI. First, add this to the top of your script:

local player = game.Players.LocalPlayer
local playerGui = player.PlayerGui

Then just switch starterGui with playerGui

Have a great day!

3 Likes

that didn’t work, and then I tried

local player = game.Players.LocalPlayer
local playerGui = player.PlayerGui
function Touch(hit)
    if player then
	game.Players.player.playerGui.ShopGui.Frame.Visible = true
end
script.Parent.Touched:connect(Touch)

still didn’t work no errors

so like this?

local player = game.Players.LocalPlayer
local playerGui = player.PlayerGui
function Touch(hit)
    if player then
	game.player.playerGui.ShopGui.Frame.Visible = true
end
script.Parent.Touched:connect(Touch)

because it didn’t work either

Firstly I want to say that this is formatted wrong as you need 2 ends

Now question, is this a normal script that is in a part, or a local script?

1 Like

it’s a local script in a part.

If I recall correctly, a local script won’t fire from a part in workspace

It would be best if you put it in the GUI and define the part

game.Workspace.Part_name.Touched:connect(Touch)
1 Like

would I do

local player = game.Players.LocalPlayer
game.Workspace.ShopPart.Touched:connect(hit)
	player.PlayerGui.ShopGui.Frame.Visible = true
end
script.Parent.Touched:Connect(hit)

Check mixu’s code that should work

1 Like