For some reason, the local script make visible shopgui for all players on the server.
shop localscript.
local shop = script.Parent
shop.Visible = false
local openShop = game.Workspace.ShopPart
local replStorage = game:GetService('ReplicatedStorage')
local closShop = script.Parent.Xbutton
local buy = script.Parent.BuyButton
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local canShop = true
local buyPickaxe2 = replStorage:WaitForChild('RemoteEvent2')
local function showMenu(otherPart)
local partParent = otherPart.Parent
local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
if canShop and humanoid then
humanoid.WalkSpeed = 0
canShop = false
shop.Visible = true
end
end
local function closeMenu()
localPlayer.Character.Humanoid.WalkSpeed = 16
shop.Visible = false
wait(2)
canShop = true
end
local function buyTool2()
buyPickaxe2:FireServer()
print('Event fired')
end
buy.MouseButton1Click:Connect(buyTool2)
closShop.MouseButton1Click:Connect(closeMenu)
openShop.Touched:Connect(showMenu)
OH WAIT I FIGURED OUT.
The reason why it shown to all guis because the Touched:Connect(showmenu) thing. Causing it to show all for players. Use remote events for Server to Client. This is how:
Add a remoteevent to ReplicatedStorage and Rename it ‘ShowShopGui’
Add a New script to ServerScriptService
local RemoteEvent = game.ReplicatedStorage.ShowShopGui
local openShop = game.Workspace.ShopPart
openShop.Touched:Connect(function(hit)
local Players = game:GetService("Players")
local Player = Players:GetPlayerFromCharacter(hit.Parent)
if Player then
RemoteEvent:FireClient(Player)
end
end)
Then Update the LocalScript for the Shop Gui for the client
local shop = script.Parent
shop.Visible = false
local openShop = game.Workspace.ShopPart
local replStorage = game:GetService('ReplicatedStorage')
local closShop = script.Parent.Xbutton
local buy = script.Parent.BuyButton
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local canShop = true
local buyPickaxe2 = replStorage:WaitForChild('RemoteEvent2')
local ShowShopGui = game.ReplicatedStorage.ShowShopGui
ShowShopGui.OnClientEvent:Connect(function()
local humanoid = Players.LocalPlayer.Character:FindFirstChild("Humanoid")
if canShop and humanoid then
humanoid.WalkSpeed = 0
canShop = false
shop.Visible = true
end
end)
local function closeMenu()
local humanoid = localPlayer.Character:FindFirstChild("Humanoid)
if humanoid then
shop.Visible = false
wait(2)
canShop = true
end
end
local function buyTool2()
buyPickaxe2:FireServer()
print('Event fired')
end
buy.MouseButton1Click:Connect(buyTool2)
closShop.MouseButton1Click:Connect(closeMenu))
The issue is that even if its a localScript, the part is in the workspace. Which means it detects any player’s touch.
You can simply fix the issue, with checking whether the player touched the part is the LocalPlayer
Here is the fixed script:
local shop = script.Parent
shop.Visible = false
local openShop = game.Workspace.ShopPart
local replStorage = game:GetService('ReplicatedStorage')
local closShop = script.Parent.Xbutton
local buy = script.Parent.BuyButton
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local canShop = true
local buyPickaxe2 = replStorage:WaitForChild('RemoteEvent2')
local function showMenu(otherPart)
local partParent = otherPart.Parent
local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
-- Checking if the player that touched the part is the local player
if canShop and humanoid and humanoid.Parent.Name == game:GetService("Players").LocalPlayer.Name then
humanoid.WalkSpeed = 0
canShop = false
shop.Visible = true
end
end
local function closeMenu()
localPlayer.Character.Humanoid.WalkSpeed = 16
shop.Visible = false
wait(2)
canShop = true
end
local function buyTool2()
buyPickaxe2:FireServer()
print('Event fired')
end
buy.MouseButton1Click:Connect(buyTool2)
closShop.MouseButton1Click:Connect(closeMenu)
openShop.Touched:Connect(showMenu)
Alright, thanks for the elaboration! Now let’s see what can we do. When you put a ScreenGui inside the StarterGui all players will receive the gui upon joining and that’s fine. We want to avoid that we can place the shop gui inside ReplicatedStorage/ServerStorage and by a script that is located inside the ServerScriptService we can check if the player is standing on the part or not, if the player is standing we can clone the gui and put it inside the certain player PlayerGui!
So let’s see how it works.
Server code:
local part: BasePart = path.to.part (ie: workspace.part)
local screenGui = path.to.screenGui (ie: ReplicatedStorage.gui/ServerStorage.gui)
local connection: RBXConnectionSignal
connection = part.Touched:Connect(function(h --[[ The player character part]]--)
// Here find the humanoid and use Players to GetPlayerFromCharacter (ie local player = ...)
local playerGui = player:FindFirstChild("PlayerGui")
screenGui:Clone().Parent = playerGui
end)
-- Important in order to garbage collect the signal
connection:Disconnect()
Client code:
-- Do what you want here
local closeButton = path.to.closeButton
closeButton.MouseButton1Click:Connect(function ()
// Gui:Destroy() or if bought something you can also destroy the gui
end)
This is the idea of doing the desired behavior you want. You will have to change stuff according to your usage