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.
script.Parent.Touched:Connect(function(hit) print("Hitted") if hit.Parent:FindFirstChildWhichIsA("Humanoid")then print("Human") local Char = hit.Parent local function FindChar() for _,i in pairs(game.Players:GetChildren())do if i:IsA("Player")then if i.Character == Char then i.PlayerGui.ShopGui.Shop.Visible = true print("ED") end end end end FindChar() end end)
Now the X:
script.Parent.MouseButton1Click:Connect(function(clk) script.Parent.Parent.Visible = false 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
script.Parent.Touched:Connect(function(hit) print("Hitted") if hit.Parent:FindFirstChildWhichIsA("Humanoid")then print("Human") local Char = hit.Parent local function FindChar() for _,i in pairs(game.Players:GetChildren())do if i:IsA("Player")then if i.Character == Char then game.ReplicatedStorage.RemoteEvent:FireClient(i)--this fires the remote event to that player whos gui you wanna mess with print("ED") end end end end FindChar() end end)
then in local script:
script.Parent.MouseButton1Click:Connect(function(clk) script.Parent.Parent.Visible = false end) game.ReplicatedStorage.RemoveEvent.OnClientEvent:Connect(function()--this triggers when the remote event fires game.Players.LocalPlayer.PlayerGui.ShopGui.Shop.Visible = true end)