How to disabled every players local script through server script?

Hello everyone,

I am trying to disable every player local script throw a server script
this is what i tried:

for i,v in pairs(game.Players:GetChildren()) do

if v:IsA("Player") then

v.PlayerGui.LocalScript.disable = true

end

end

Unfortunately it wont work!

Disabled is the name of the property, not disable

sorry i rushed it 30 character

I think you could use GetDescendants() for this to save a few lines.

for i,v in pairs(game.Players:GetDescendants()) do
    if v:IsA("LocalScript") do
        v.Disabled = true
    end
end

still wont work …

wont work 30 characterss…

When/where are you running this code?
Are there any errors in the output window?
Are you sure that the code isn’t run before the player has the script and/or before the player has even joined the server?

i think its because the code runs before the player joins

What is the point of disabling all scripts though? You could do this as GUIs reset whenever a character respawns:

local Player = game.Players.LocalPlayer
Player.CharacterAdded:Connect(function()
    for i,v in pairs(Player.GetDescendants()) do
        if v:IsA("LocalScript") do
            v.Disabled = true
        end
    end
end)

Note: That should be in a LocalScript. You mentioned you wanted to do it server side, but could you tell us why? What is your objective? This would be for a server-sided script:

game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function()
        wait(1)
        for i,v in pairs(Player.GetDescendants()) do
            if v:IsA("LocalScript") do
                v.Disabled = true
            end
        end
    end)
end)

i have a regenerate server script which regenerates a model and the local script i want to disable is a mover that moves the model but what happens is whenever the regeneration happens the local script stops working.

local function regenerate()
    for i,v in pairs(game.Players:GetPlayers()) do
        v.PlayerGui.ScreenGui.LocalScript.Disabled = true --Change it depending on the name of your GUI.
    end
end

regenerate() --Call this function when you want to regenerate.

I believe this should work, but it depends on how you set it up.

dont work heres how i applied:

object = script.Parent
if (object ~= nil) and (object ~= game.Workspace) then 
model = object 

backup = model:clone()  
waitTime = script.Parent.Time.Value
wait(1)

while true do 
wait(waitTime+2) 

model:remove()

model = backup:clone()
wait(2)
model.Parent = game.Workspace 
model:makeJoints()
local function regenerate()
    for i,v in pairs(game.Players:GetPlayers()) do
        v.PlayerGui.ScreenGui.LocalScript.Disabled = true --Change it depending on the name of your GUI.
    end
end

regenerate()
end
end

If you’re disabling local scripts from a server script, I’m more than certain that the server script wont be able to disable all the script you want to disable because of how Server and Client Interaction works.

I would recommend just using :GetPlayers() instead of :GetChildren() due to the fact that it will only get players, hence it’s function name. :wink:

Already found my solution but thank you!

Your code should be:

local Players = game:GetService("Players")

for _, v in pairs(Players:GetPlayers()) do

v.PlayerGui.LocalScript.Disabled = true

end

Make a loop trought all the players, for each player fire a remote event to that client. and in another local script, you can make a remoteEventPatch.OnClientEvent:Connect(function() and in the function write a simple loop to all the local scripts you want to disable, and in the loop write v.Disabled = true
Example:

--Server script:

local remote = --local scripts remover, remote patch

for a,b in pairs(game.Players:GetChildren()) do
    remote:FireClient(b)
end

--Local script:

local remote = --local scripts remover, remote patch
local localScripts = {"This is the local scripts table, insert here the local scripts' patch of the local scripts you want to remove"}

remote.OnClientEvent:Connect(function()
    for a,b in pairs(localScripts) do
        b.Disabled = true
    end
end)

With this method the whole thing should work. Anyways i hope this helped. :+1:

1 Like

I think it would be better to use remote:FireAllClients

3 Likes

Yes, you are right, i didn’t tought at it.
Anyways, yes it’s better to use :FireAllClients, instead of looping the players.