I have a whitelist script. When the people on whitelist arent the local player, it destroys the script. Well, thats what im trying to do… For some reason its not working, and it runs the script like normal.
local plr = game.Players.LocalPlayer
local whitelist = {"GoodGuy21938"}
if table.find(whitelist, plr.Name) then --its when it finds the player for testing
script:Destroy()
print("test") --it even prints this.
end
I believe that is because LocalScripts cannot call the :Destroy() method, though I am not 100% sure of how true this is. In any case, I believe you should use a RemoteEvent so that the server can destroy the script. Otherwise, I believe this won’t work.
This does not work because Scripts do not have the :Destroy function inside of them, as that is only for models. You can try doing this instead:
local plr = game.Players.LocalPlayer
local whitelist = {"GoodGuy21938"}
if table.find(whitelist, plr.Name) then --its when it finds the player for testing
script.Enabled = false --disables the script
print("test") --it even prints this.
end
This is the only property that you can use to stop the script functioning.
just do this in a server script that is in serverscriptservice and it should work, sorry if i forgot something i typed this on phone :
local Players = game:GetService("Players")
local Whitelist = {"GoodGuy21938"}
Players.OnPlayerAdded:Connect(function(plr)
if table.find(Whitelist, plr.Name) then
plr.ScriptName:Destroy()
print(plr.. " has the script destroyed")
end
end)
also if the script is in the character then just make it like this:
local Players = game:GetService("Players")
local Whitelist = {"GoodGuy21938"}
Players.OnPlayerAdded:Connect(function(plr)
plr.Character.OnCharacterAdded(function(char)
if table.find(Whitelist, plr.Name) then
char.ScriptName:Destroy()
print(plr.. " has the script destroyed")
end
end
end)
(again srry about the formatting i have no tab key)
its inside of a gui in the playergui. I tried this and it still has the script in the gui.
local Players = game:GetService("Players")
local Whitelist = {"GoodGuy21938"}
Players.PlayerAdded:Connect(function(plr)
if table.find(Whitelist, plr.Name) then
plr.PlayerGui.Freecam.FreecamScript:Destroy()
print(plr, " has the script destroyed")
end
end)
Every Instance createable by a developer can also be destroyed. Check the documentation for “BaseScript”. OP’s problem is that PlayerAdded doesn’t fire the LocalPlayer since the LocalPlayer was created after the connection was made.