I am trying to make a script where when you touch a certain part, a GUI pops up on your screen. However, it has not been working in thew actual game, and not in the playtest. Please help me! This is my code:
script.Parent.Touched:Connect(function(hit) if hit.Name == "Left Foot" then game.StarterGui.Shop.Frame.Visible = true end end)
Please read this short article excerpt.
StarterGui
is not the authentic household of the GUI Objects, to actively modify the local User Interface, you have to access the PlayerGui
container of a Player Object. Fortunately, the .Touched
signal's Hit
parameter can be used to pull a Player Object from the Instance of contact, which is a piece of your Character Rig.
local Players = game:GetService("Players") local Part = script.Parent local function OpenGui(Hit) local Humanoid = Hit.Parent:FindFirstChildOfClass("Humanoid") if (Humanoid) then local Player = Players:GetPlayerFromCharacter(Hit.Parent) if (Player) then local PlayerGui = Player:WaitForChild("PlayerGui") local Shop = PlayerGui:WaitForChild("Shop") local Frame = Shop:WaitForChild("Frame") Frame.Visible = not (Frame.Visible) end end end Part.Touched:Connect(OpenGui)
If this works for you, don't forget to accept this answer!