So i heard that script runs fkr the server so lets say i made a textbutton and it has a script to open shop gui and if a player clicks it will it open the shop for every people on the server?
Does Script will effect the whole server of people?
2 answers
Each player has their own copy of a gui in their player gui. If you click a button in a shop, it will open up the shop for only you.
If you write the code for clicking the button in a localscript, the server will not be able to see that your shop is open.
If you write the code for clicking the button in a server script, the server WILL be able to see that your shop is open. (but it will still only show up on your screen)
If you want to have the shop show up on everyone's screen, you can use remote events or you can do the following from a server script:
for _, player in pairs(game.Players:GetPlayers())do
local playerGui = player.PlayerGui
local gui = playerGui:WaitForChild("TheNameOfTheShopGuiGoesHere")
gui.Visible = true -- make the gui visible however you do that.
end
No. You would need to use a RemoteEvent and tell the server to show the Gui on every players screen. This is because LocalScripts will only affect that player. You can use game:GetService("Players").LocalPlayer to get a variable of that specific player you are affecting. By using a RemoteEvent, you can loop through all the players in the server and toggle the Gui for every player in the server.
--LocalScript
script.Parent.MouseButton1Click:Connect(function()
remoteEvent:FireClient()
end)
--ServerScript
remoteEvent.OnServerEvent:Connect(function(clickedPlayer)
print(clickedPlayer.Name .. " clicked the Gui!")
for _, player in pairs(game:GetService("Players"):GetPlayers()) do
player.PlayerGui.ScreenGui.Frame.Visible = true --edit the Gui path here
end
end)
By using the code above, in the specified script types, you can tell the server to change the visibility of the Gui on all players screen. FireClient() passes the player parameter by default so you can easily tell which player specifically clicked the Gui. Hope this helps!
This discussion is preserved as it was. New answers, comments, and votes are closed.
