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!
@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.
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.
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.
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.
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.
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!.
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.