I'm trying to make a shop and I put an invisible part infront of the shop so once a player stands on it, it will show the GUI and once they step off it will close the GUI. However my code doesn't even open the GUI and I'm not sure what the problem is.
I'm new to Roblox coding so im not sure how to make this happen. Here's my LocalScript code:
local GunShopFrame = script.Parent GunShopFrame.Visible = false workspace.openPart.Touched:Connect(function() GunShopFrame.Visible = true end) workspace.closePart1.Touched:Connect(function() GunShopFrame.Visible = false end) workspace.closePart2.Touched:Connect(function() GunShopFrame.Visible = false end) workspace.closePart3.Touched:Connect(function() GunShopFrame.Visible = false end)
There's multiple ways to go about this. I'm going to assume you're using a localscript, because you're referencing script.Parent, which is typically a GUI.
The best method would likely be a client event, which is basically an event that you can fire from the server to the client.
It's defined typically in localscripts.
game.ReplicatedStorage.gui_appear.OnClientEvent:Connect(function(vis) local appearing_frame = script.Parent -- Just reference the frame you want to appear. appearing_frame.Visible = vis end)
On the server, you'd want to input the .Touched events, because it can only fire on the server.
workspace.openPart.Touched:Connect(function(hit) local plr = game.Players:GetPlayerFromCharacter(hit.Parent) game.ReplicatedStorage.gui_appear:FireClient(plr,true) end) workspace.closePart1.Touched:Connect(function(hit) local plr = game.Players:GetPlayerFromCharacter(hit.Parent) game.ReplicatedStorage.gui_appear:FireClient(plr,false) end) workspace.closePart2.Touched:Connect(function(hit) local plr = game.Players:GetPlayerFromCharacter(hit.Parent) game.ReplicatedStorage.gui_appear:FireClient(plr,false) end) workspace.closePart3.Touched:Connect(function(hit) local plr = game.Players:GetPlayerFromCharacter(hit.Parent) game.ReplicatedStorage.gui_appear:FireClient(plr,false) end)
There is likely a better way to go about this, but this is the simplest.