Script not working?

Hello, im pocvq or monke according to my display name today i was trying to script a part that makes a shop gui visible when its touched but for some reason my script isnt working and there is no errors or text from it in the output

Here is the script:
local gui = game.StarterGui.Shop.ShopFrame
local plr = game.Players.LocalPlayer
local part = game.Workspace.ActShop

part.Touched:Connect(function(hit)
if hit then
gui.Visible = true
else
warn(“Error”)
end
end

Any help is appreciated!

3 Likes
local plr = game.Players.LocalPlayer
local gui = plr.PlayerGui.Shop.ShopFrame
local part = game.Workspace.ActShop

part.Touched:Connect(function(hit)
if hit then
gui.Visible = true
else
warn(“Error”)
end
end)

This should work

For some reason it didnt work and there is still no errors in the output

Where is this script located?
You might try adding a WaitForChild() for the PlayerGui as it might not load sometimes because of some problems.

1 Like

The script is located inside the part and its a localscript

Is the part located in Workspace? If so, then the script wont run, so try moving it to StarterPlayer.StarterCharacterScripts.

1 Like

Ok i will try that i will tell you if it works

You have to use a TouchedEvent in a server script inside the part. When the part is touched, it fires a remote event to the player that touched it. When the client receives the message (remote event) it opens the shop Gui. Simply add a close button in the shop gui and your good to go.

1 Like

As @inurentto local scripts don’t run in the workspace thus you should parent it to another service such as StarterGUI or StarterCharacterScripts etc.

1 Like

Yea i didnt know this lol thanks im trying a bunch of suggestions rn

As it is on a local script when the part is touched it will connect to that certain player.
If it was in a server script then you had to fire a remote event.
Local scripts can do the work by themselves.

1 Like

It worked thank you guys so much!!!

Glad to hear that the script is working! Make sure you mark a reply as a solution so that others know that the problem was solved.

Ok i dont normally post on here so will do thanks