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?
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.
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.
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.