Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to disable a script in ServerScriptService?

I am creating a Group Lock System on Roblox with a button that turns it off. The button has a script that disables the group lock system in PlayerGui. However, it doesn't turn off the script. What is happening?

My current script:

script.Parent.Activated:connect(function()
	local stafflock = game.ServerScriptService.Stafflock
	local status = "on"
	
	stafflock.Disabled = true
	
	game.StarterGui:SetCore("SendNotification", {
		Title = "Stafflock";
		Text = "Has been turned"..status..".";
		Duration = 5;
	})
end)

Thanks.

4 comments

0

It is a local script? If it is you may need a remote event

0

Could you give more info,like if the script.Parent is a tool or something like that?

0

It is a button. And yes, it is a local script.

0

i updated my answer

2 answers

script.Disabled is untrustworthy and usually doesn't work as intended. You could use :Destroy() instead.

Accept this if it worked!

How would you use it?

Just replace

stafflock.Disabled = true

with

stafflock:Destroy()

NOTE: :Destroy() completely destroys/deletes something.

2 comments

0

didn't work

0

it should, are you destroying the script like this: stafflock:Destroy()

First thing, you cannot access ServerScriptService and ServerStorage in client-side, so son't index them directly from Local Script. Try using a Remote Event.

game.ReplicatedStorage.RemoteEvent:FireServer() -- Change it to your Remote Event name.

Next, add a script in ServerScriptService and do this:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function()
	script.Parent.StaffLock.Disabled = true
end)

This is how your Local Script must look:

script.Parent.Activated:connect(function()
    local status = "on"

    game.ReplicatedStorage.RemoteEvent:FireServer() -- Change the remote event to that you will be using

    game.StarterGui:SetCore("SendNotification", {
        Title = "Stafflock";
        Text = "Has been turned"..status..".";
        Duration = 5;
    })
end)

Lemme know if it helps!

This discussion is preserved as it was. New answers, comments, and votes are closed.