1 | script.Parent.Touched:connect( function () |
2 | if game.StarterGui.Shop.Background.Visible = = false |
3 | then |
4 | game.StarterGui.Shop.Background.Visible = true |
5 | end |
6 | end ) |
7 |
8 | --It's pretty simple, when someone clicks the brick, the background of a shopgui becomes visible. what's broken? |
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
01 | Background = game.StarterGui.Shop.Background |
02 |
03 | function onClicked(mouse) |
04 | if Background.visible = = false |
05 | then |
06 | Background.Visible = true |
07 | end |
08 | end |
09 |
10 | script.Parent.ClickDetector.MouseClick:connect(onClicked) |
I Hope This Helped You!
01 | script.Parent.ClickDetector.MouseClick:connect( function (plr) |
02 | local player = game.Players:WaitForChild(plr.Name) |
03 | local gui = player.PlayerGui |
04 |
05 | if gui.Shop.Background.Visible = = false then |
06 | gui.Shop.Background.Visible = true |
07 | else |
08 | gui.Shop.Background.Visible = false |
09 | end |
10 | 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
1 | script.Parent.Touched:connect( function (hit) --Hit is what touches the part. |
2 | if game.Players:GetPlayerFromCharacter(hit.Parent).PlayerGui.Shop.Background.Visible = false --we get the Player from game.Players |
3 | then |
4 | game.Players:GetPlayerFromCharacter(hit.Parent).PlayerGui.Shop.Background.Visible = true |
5 | end |
6 | end ) |
That should be it! Hope this helped!!!