Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is my localscript running for other players?

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.

1 comment

0

Make sure FE is enabled.

1 answer

✓ Accepted answer

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)

1 comment

0

Accept his answer...

This discussion is preserved as it was. New answers, comments, and votes are closed.