How to disable a script

Hello! So I am trying to make a button you can click that disables a script, and it works. The script I disabled spins the player in a circle but when disabled, the player stops in mid-air. How would I fix this?

Disable script:

local Player = game.Players.LocalPlayer
local PlayerScripts = Player:WaitForChild("PlayerScripts")

script.Parent.MouseButton1Click:Connect(function()
	local SpinScript = PlayerScripts:WaitForChild("SpinScript", 5)
	if SpinScript then
		print("script found")
		SpinScript:Destroy()
	end
end)

Spin script:

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart", 5)

while task.wait(0.1) do
	HumanoidRootPart.Orientation += Vector3.new(0, 1, 0)
end

If you think you know what went wrong, please let me know. Thank you and have a wonderful day! :slight_smile:

5 Likes

Try doing SpinScript.Enabled = false

3 Likes

Are these both local scripts? I may be wrong but I think you might only be able to delete the script through a normal/server script.

@LucaDaBoy Funnily enough, I changed it right before you posted lol.

Now that my script is disabled, I want the player to stand on the ground instead of being suspended in the air. And when they click the button again, they will resume spinning.
image
How would I do this?

@PolyLacticSugarcane Yes, they are both local scripts. I tried using the disable script on the sever but that didn’t work.

It seems like your character is anchored, is this true or do you fall down?

1 Like

The character is not anchored.

To disable and re-enable the script you can run this code:

SpinScript.Enabled = not SpinScript.Enabled
This will toggle enable/disable.

Next up to fix the player being in the air you could teleport them to the ground after toggling disable on the script.

1 Like

Sorry, but that didn’t seem to work.

How would I do this?

For the first one try making an if statement, if the script is enabled then disable it and the other way around. For the teleporting i’m not sure.

1 Like

Nvm mind I made a fix and that line works now :slight_smile:

1 Like

I tried teleporting the player to a part that expanded across the map whenever they pressed the button, but that didn’t work at all. The player would land on their head and scoot across the ground lol.

1 Like

Could you send me what you have?

1 Like

Disable script:

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local HRP = Character:WaitForChild("HumanoidRootPart", 5)
local PlayerScripts = Player:WaitForChild("PlayerScripts")

local TelePart = game.Workspace:WaitForChild("TelePart", 5)

script.Parent.MouseButton1Click:Connect(function()
	local SpinScript = PlayerScripts:WaitForChild("SpinScript", 5)
	if SpinScript then
		print("script found")
		SpinScript.Enabled = not SpinScript.Enabled
		
		if Humanoid then
			HRP.CFrame = TelePart.CFrame
		end
	end
end)

Spin script:

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart", 5)

while task.wait(0.1) do
	HumanoidRootPart.Orientation += Vector3.new(0, 1, 0)
end

The only thing I need to fix now is making the player stand up when the spin script is disabled.

1 Like

To make the player stand up when the spin script is disabled, you can set the Humanoid’s AutoRotate property to true. This will make the character automatically stand upright when not moving.

--Disable script:

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local HRP = Character:WaitForChild("HumanoidRootPart", 5)
local PlayerScripts = Player:WaitForChild("PlayerScripts")

local TelePart = game.Workspace:WaitForChild("TelePart", 5)

script.Parent.MouseButton1Click:Connect(function()
	local SpinScript = PlayerScripts:WaitForChild("SpinScript", 5)
	if SpinScript then
		print("script found")
		SpinScript.Enabled = not SpinScript.Enabled
		
		if SpinScript.Enabled then
			Humanoid.AutoRotate = false
		else
			Humanoid.AutoRotate = true
		end
		
		if Humanoid then
			HRP.CFrame = TelePart.CFrame
		end
	end
end)
-Spin script:

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart", 5)

while task.wait(0.1) do
	HumanoidRootPart.Orientation  = Vector3.new(0, 1, 0)
end

In the Disable script, I added a condition to check if the SpinScript is enabled or not. If it’s enabled, I set the AutoRotate property of the Humanoid to false, which disables the automatic upright orientation. If the SpinScript is disabled, I set AutoRotate to true, which enables the automatic upright orientation.

1 Like

I would put that script in a function and make a value when you want to disable it. If the value is set to true then you can end the function, therefor disabling the script. Hope it helps!.

1 Like

@qw3rty_l0l It made the player still, but it didn’t put them upright.

@keckts Sorry, but I’m not exactly understanding what you mean.

Never mind sorry, I didn’t see the other script you just posted have a good day!.

1 Like
script.Enabled = false

Sometimes script.Enabled = false works. Sometime it will not. I’m not sure why (I kind of know).
But, that don’t matter because if you call that from a different script it will work (I think).
Had problems with this once and if I remember right that’s how I got around that.

1 Like

So should I use:

SpinScript.Enabled = not SpinScript.Enabled

or this?:

script.Enabled = false