Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Why is my localscript running for other players?

Asked by
Faazo 84
6 years ago
Edited 6 years ago

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.

0
Make sure FE is enabled. CodyDev 70 — 6y

1 answer

Log in to vote
1
Answered by
lukeb50 631 Moderation Voter
6 years ago

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)
0
Accept his answer... DaWarTekWizard 169 — 6y
Ad

Answer this question