script.Parent.Touched:connect(function()
if game.StarterGui.Shop.Background.Visible == false
then
game.StarterGui.Shop.Background.Visible = true
end
end)
--It's pretty simple, when someone clicks the brick, the background of a shopgui becomes visible. what's broken?
What's wrong with this level 1 easy script?!
3 answers
You said when they click the brick. In this situation you need a Clickdetector! Insert a click detector in the part. The code should be like this
The Function Is A OnClicked, Not An OnTouched
It Is Also Easier to Define and Could Make It More efficent
Background = game.StarterGui.Shop.Background
function onClicked(mouse)
if Background.visible == false
then
Background.Visible = true
end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
I Hope This Helped You!
script.Parent.ClickDetector.MouseClick:connect(function(plr)
local player = game.Players:WaitForChild(plr.Name)
local gui = player.PlayerGui
if gui.Shop.Background.Visible == false then
gui.Shop.Background.Visible = true
else
gui.Shop.Background.Visible = false
end
end)
This problem is quite simple! You are accessing the StarterGui which is not what you want for live events. Instead you need the PlayerGui. This can be accomplished using the :GetPlayerFromCharacter() method
script.Parent.Touched:connect(function(hit)--Hit is what touches the part.
if game.Players:GetPlayerFromCharacter(hit.Parent).PlayerGui.Shop.Background.Visible = false--we get the Player from game.Players
then
game.Players:GetPlayerFromCharacter(hit.Parent).PlayerGui.Shop.Background.Visible = true
end
end)
That should be it! Hope this helped!!!
2 comments
I'll test it. Thanks to all of you! But, why isn't it StarterGui when it's IN the startergui?
StarterGui is what puts the guis into all the player's perosonal guis
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
Thanks, but it still didn't help. Could it be there's another script interfering with this one?
Is there anything popping up in the output?
function onClicked(mouse) if game.StarterGui.Shop.Backg:8: attempt to index global 'script' (a nil value)
Another Script could Be Interfering Let Me Update My Answer