I have a game I'm developing, and I'm making a shop in it for armor and swords. When you enter a region specified by a blue circle, it SHOULD open a gui. It works once, and then doesn't run. It says it's done with the code, but nothing's appearing.
I think it might have something to do with the X script. I'll post it as well.
01 | script.Parent.Touched:Connect( function (hit) |
02 | print ( "Hitted" ) |
03 | if hit.Parent:FindFirstChildWhichIsA( "Humanoid" ) then |
04 | print ( "Human" ) |
05 | local Char = hit.Parent |
06 | local function FindChar() |
07 | for _,i in pairs (game.Players:GetChildren()) do |
08 | if i:IsA( "Player" ) then |
09 | if i.Character = = Char then |
10 | i.PlayerGui.ShopGui.Shop.Visible = true |
11 | print ( "ED" ) |
12 | end |
13 | end |
14 | end |
15 | end |
16 | FindChar() |
17 | end |
18 | end ) |
Now the X:
1 | script.Parent.MouseButton 1 Click:Connect( function (clk) |
2 | script.Parent.Parent.Visible = false |
3 | end ) |
(The X's script is Local)
Playerguis can only be accessed using client side scripts, so to do this, we use a remote event, so the server script looks like this:
add a remote event to game.ReplicatedStorage and name it whatever oyu want, ill use the name remote event for this script to not confuse you
01 | script.Parent.Touched:Connect( function (hit) |
02 | print ( "Hitted" ) |
03 | if hit.Parent:FindFirstChildWhichIsA( "Humanoid" ) then |
04 | print ( "Human" ) |
05 | local Char = hit.Parent |
06 | local function FindChar() |
07 | for _,i in pairs (game.Players:GetChildren()) do |
08 | if i:IsA( "Player" ) then |
09 | if i.Character = = Char then |
10 | game.ReplicatedStorage.RemoteEvent:FireClient(i) --this fires the remote event to that player whos gui you wanna mess with |
11 | print ( "ED" ) |
12 | end |
13 | end |
14 | end |
15 | end |
16 | FindChar() |
17 | end |
18 | end ) |
then in local script:
01 | script.Parent.MouseButton 1 Click:Connect( function (clk) |
02 | script.Parent.Parent.Visible = false |
03 | end ) |
04 |
05 |
06 | game.ReplicatedStorage.RemoveEvent.OnClientEvent:Connect( function () --this triggers when the remote event fires |
07 |
08 | game.Players.LocalPlayer.PlayerGui.ShopGui.Shop.Visible = true |
09 |
10 | end ) |