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

How to make function onClick() disable a script permanently?

I made a script that's supposed to disable a script, as well as its subscripts and sounds inside it, and play a message when the button is clicked.

However, after disabling the script and its contents, it re-enabled it. I want the script to be disabled permanently upon clicking the button.

S1 = game.Workspace.SDS

function onClick()
	S1.Disabled = true
	S1.SDS2.Disabled = true
	S1.Alarm0:Stop()
	S1.Alarm1:Stop()
	S1.Alarm2:Stop()
	S1.Alarm3:Stop()
	S1.Alarm4:Stop()
	S1.Fire:Stop()
	S1.movement:Stop()
	script.Parent.ClickDetector.MaxActivationDistance = 0

local hint = Instance.new("Hint", game.Workspace)

hint.Text = "Script Turned Off."
end
script.Parent.ClickDetector.MouseClick:connect(onClick)

4 comments

1

Why not just destroy the script then?

0

I'll be needing the script after it's disabled eventually, as there will be another button to re-enable the script.

1

Why separate scripts, when you can just compact them together with their own separate functions?

0

Actually, I think that would work. Resolved.

2 answers

An easy way to do this would be to use a bool value and check if it is true at the beginning of every script. That way you can just have it change the bool value.

I would start the script with an if then statement with a variable that only allows the function to run if its true. Once the script has run once, you can set the variable to false, therefore not allowing the script to run until you make the variable true again.

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