I am trying to destroy this script after clicking the button. I’ve also tried using Disabled and it doesn’t seem to work. I have other code running using the same function (if the button is pressed a sound will play/stop) and it works.
Button.MouseButton1Click:Connect(function() -- Once the player clicks the button, this function fires a remote event
game.Workspace.menuBlur:Destroy()
end)
That button is a GUI button, right? And you are really firing the remote event to a Server Script in order to destroy the script? or you are trying to destroy it using the client localscript?
Im not really sure that you can destroy a server script from a client localscript. You should try to use a remote and let a server script destroy it, otherwise, even if you are able to destroy it, the change will not be taken by the server, and only for that client. I still dont think that u can destroy a server element from the local script
I see. For that you will need to use an event because if you try to destroy server sided stuff from the client it won’t work as the client can’t see those things
Look, even if you delete it from client tree, still exist in server, so useless if you really want to remove the script from server
Im using the code u provided to place it on a button, and it does as expected, delete the script only on client and still exist in server
The first one is impossible. Its a server script inside workspace, loads even firstly than the client joining and the local script in the player.
Then, unless u can click the button before server exist, theres no way that the first option you saying happens.
On the option 2 you said. I guess FE right now does nothing, its impossible to turn it off. Thats what I’d read.
(Another thing, even if is possible to disable FE, its a very very bad idea doing it…)
Just create a remote event, fire it using the GUI button, get the signal on a server script and use that server script to delete/disable the script you want
local RepS = game:GetService("ReplicatedStorage")
local delScript = RepS:WaitForChild("DeleteScript")
local Button = script.Parent.TextButton
Button.MouseButton1Click:Connect(function()
--game.Workspace.ToDelete:Destroy()
delScript:FireServer()
end)
Server Script inside ServerScriptService:
local RepS = game:GetService("ReplicatedStorage")
local delScript = RepS:WaitForChild("DeleteScript")
local scriptToDel = game.Workspace.ToDelete
local function delNow()
-- Disable
scriptToDel.Disabled = true
-- Or Destroy it
scriptToDel:Destroy()
end
delScript.OnServerEvent:Connect(delNow)
To the best of my knowledge, Script instances (server scripts) are not even replicated to the client. Thus, you need some sort of client-server communication to delete one from a LocalScript.