So I have this localscript that opens a shop in the player's screen but when i run a test with 2 players both players got the shop gui when only one player touched the shop opener. Its a local script so I don't see why both players are getting the gui. Here is the script:
Players = game:GetService("Players") LocalPlayer = Players.LocalPlayer PlayerGui = LocalPlayer.PlayerGui Detector = game.Workspace.ShopDetector RS = game:GetService("ReplicatedStorage") ShopOpen = false Detector.Touched:Connect(function() if ShopOpen == false then RS.Shop:Clone().Parent = game.Players.LocalPlayer.PlayerGui ShopOpen=true end end) PlayerGui.ChildRemoved:Connect(function() ShopOpen = false end)
I thought localscripts only run for the individual client... I'm really confused and questioning what localscript really is. Help is greatly appreciated.
Because you don't check who touched it. Whenever anything touches the opener, all the localscripts detect it and open the shop.
Players = game:GetService("Players") LocalPlayer = Players.LocalPlayer PlayerGui = LocalPlayer.PlayerGui Detector = game.Workspace.ShopDetector RS = game:GetService("ReplicatedStorage") ShopOpen = false Detector.Touched:Connect(function(touch) if ShopOpen == false and touch.Parent.Name==LocalPlayer.Name then RS.Shop:Clone().Parent = game.Players.LocalPlayer.PlayerGui ShopOpen=true end end) PlayerGui.ChildRemoved:Connect(function() ShopOpen = false end)