I got a problem with my script
i need to make it like when you click on GUI button all players got disabled localscript from other gui
but i don’t know how to do that
i try’d my best but nothing and i need help with it
i just noticed that i type Enable except of Enabled but still it wont work
script.Parent.MouseButton1Click:Connect(function()
local Smaller = game.Players.MaxPlayers.PlayerGui.SettingsOpened.Things
if script.Parent.TextColor3 == Color3.fromRGB(255,0,0) then
script.Parent.TextColor3 = Color3.fromRGB(0,255,0)
Smaller.AcceptMusic.LocalScript.enabled = false
elseif script.Parent.TextColor3 == Color3.fromRGB(0,255,0) then
script.Parent.TextColor3 = Color3.fromRGB(255,0,0)
Smaller.AcceptMusic.LocalScript.enabled = true
end
end)
Anyone know how to fix this? And thanks you for trying to help me
You cannot access the client from server anymore due to Filtering Enabled.
You should use remote events in this case and there are very helpful tutorials out there on youtube
Also I would like to add that there are many errors in the script itself
MaxPlayers is a property stating how many Players the current server can hold.
For this, you’ll want to integrate a RemoteEvent because not only are UIs cloned locally but any changes done on this client won’t replicate. Then on the server, you’ll want to iterate through GetPlayers and FireClient the RemoteEvent to tell the client to make their LocalScript Disabled.
For example:
--// LocalScript, inside Button
local RemoteEvent = game:GetService("ReplicatedStorage").RemoteEvent
script.Parent.MouseButton1Click:Connect(function()
RemoteEvent:FireServer(script.Parent.TextColor3) --// Pass the color over to the server
end)
--// Script, ServerScriptService
local Players = game:GetService("Players")
local RemoteEvent = game:GetService("ReplicatedStorage").RemoteEvent
RemoteEvent.OnServerEvent:Connect(function(Player, Color)
for _, LoopPlayer in ipairs(Players:GetPlayers()) do
RemoteEvent:FireClient(LoopPlayer, Color)
end
end)
From there you can put a callback to OnClientEvent of the RemoteEvent and set Disabled of the LocalScript to true.
from your code you are using enabled instead of Enabled
if its the server i usually do a loop so i dont have to do anything more complicated
script.Parent.MouseButton1Click:Connect(function()
for i, v in pairs(game.Players:GetPlayers()) do
-- second hand lets get the smaller variable
local Smaller = v.MaxPlayers.PlayerGui.SettingsOpened.Things
if script.Parent.TextColor3 == Color3.fromRGB(255,0,0) then
script.Parent.TextColor3 = Color3.fromRGB(0,255,0)
Smaller.AcceptMusic.LocalScript.Enabled= false -- we developers always use Enabled
elseif script.Parent.TextColor3 == Color3.fromRGB(0,255,0) then
script.Parent.TextColor3 = Color3.fromRGB(255,0,0)
Smaller.AcceptMusic.LocalScript.enabled = true
end
end
end
end)
this code should be server-sided if it was local then we could just get player by game.Players.LocalPlayer