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

How can i get all of the players to freeze instead of only me?

Asked by 4 years ago

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.

1
Please use Lua Code Blocks as this code is not easy to read. https://scriptinghelpers.org/help/how-post-good-questions-answers (Scroll To The Bottom Of That Page) killerbrenden 1537 — 4y

2 answers

Log in to vote
0
Answered by
Norbunny 555 Moderation Voter
4 years ago
Edited 4 years ago

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.

Ad
Log in to vote
0
Answered by
haba_nero 386 Moderation Voter
4 years ago

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

Answer this question