Im trying to do if this button pressed then freeze every local player. This is my script script.Parent.Frame.PlayersTrollFrame.FreezePlayers.MouseButton1Click:Connect(function() local player = game.Players.LocalPlayer local character = player.Character local RootPart = character:WaitForChild("HumanoidRootPart") game.Players:GetPlayers()RootPart.Anchored = true script.Parent.Freeze.Visible = true end) im not sure why does it freeze only me since it is getting all of the players connected to the game, it only freezes me.
You are running all of this in a local scripting, meaning that any code written there will only happen localy. You will need to learn using Remote Events in order to fire the server to freeze players.
Second thing, LocalPlayer
only exists in the local script, and it returns your player, yourself.
game.Players:GetPlayers()RootPart.Anchored = true script.Parent.Freeze.Visible = true end)
isn't doing anything. GetPlayers()
returns a table with all the players in-game.
I would suggest reading more about GetPlayers() and Remote Events before proceeding.
Also, in order to format your code, click at the Lua
icon at the top of the editor.
Hello! I will have you back on track Easy as 1, 2, 3!
1
You need to make a RemoteEvent called "FreezeEveryone" in ReplicatedStorage
2
Put this code in the button in a LocalScript
script.Parent.MouseButton1Click:Connect(function() game.ReplicatedStorage:FindFirstChild("FreezeEveryone"):FireServer() end
3 Put this Script in ServerScriptService
game.ReplicatedStorage:FindFirstChild("FreezeEveryone").OnServerEvent:Connect(function() for i,plr in pairs(game.Players:GetPlayers()) do local Char = plr.Character:FindFirstChild("HumanoidRootPart") Char.Anchored = true end end
Hope this works for you! If you have any questions, comment below!
Best,
TheLastHabanero