Script disable not working

Hi guys! :slight_smile:

Why is the script not working well?
I searched up on Google about it, but nothing useable information about it, what I’ve found.
And how can I make the aiming more smoother?

So here is a video + a picture and a script:
https://doy2mn9upadnk.cloudfront.net/uploads/default/original/4X/f/5/2/f52f52fb109135325900375249efb0dadcfa6c0a.mp4

Képkivágás

--Aim script

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local held = false
mouse.Button2Down:connect(function(ZoomIn)
     held = true
	game.Workspace.Camera.FieldOfView = game.Workspace.Camera.FieldOfView - 15.6
	game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed - 1
	script.Parent.Camera.Disabled = false
end)

mouse.Button2Up:connect(function(ZoomOut)
     held = false
	game.Workspace.Camera.FieldOfView = game.Workspace.Camera.FieldOfView + 15.6
	game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed + 1
	script.Parent.Camera.Disabled = true
end)

spawn(function(ZoomIn)
     while true do
         wait(.5)
     end
end)
--Created by: ImFarley 

--//THIRD PERSON SHOOTER CAMERA SCRIPT\\--

local uis = game:GetService("UserInputService")
local ts = game:GetService("TweenService")
local cam = workspace.CurrentCamera
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
repeat wait() until plr.Character and plr.Character.Parent == workspace

local char = plr.Character
local hum = char:WaitForChild("Humanoid")
local waist = char.UpperTorso:WaitForChild("Waist")
local root = char:WaitForChild("HumanoidRootPart")

hum.CameraOffset = Vector3.new(3, 0, 0)
hum.AutoRotate = false
cam.CameraSubject = hum

game:GetService("RunService").RenderStepped:Connect(function()
uis.MouseBehavior = Enum.MouseBehavior.LockCenter
local delta = uis:GetMouseDelta()
local deltaX, deltaY = delta.X, -delta.Y
cam.CFrame = CFrame.new(cam.CFrame.p, cam.CFrame* CFrame.new(deltaX, deltaY, -2000).p)

local offset = char.LowerTorso.CFrame:ToWorldSpace(CFrame.new(0, char.UpperTorso.Size.Y/2, 0)) * CFrame.fromEulerAnglesXYZ(math.max(math.min(math.asin((mouse.Hit.p - mouse.Origin.p).unit.y), .6), -.75), 0, 0) * CFrame.new(0, char.UpperTorso.Size.Y/2, 0)

waist.C1 = offset:inverse() * char.LowerTorso.CFrame * CFrame.new(0, .8, 0)

local tweenInfo = TweenInfo.new(.15, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)
local newRootCF = CFrame.new(root.CFrame.p,root.CFrame.p+Vector3.new(cam.CFrame.lookVector.X,0,cam.CFrame.lookVector.Z))
local tween = ts:Create(root, tweenInfo, {["CFrame"] = newRootCF}, true)
tween:Play()
end)

2 Likes

I would try replacing this whole system with something that uses bindables. Disabling/enabling scripts seems like really hacky way to run code from other scripts, and in most cases the same functionality can be achieved with event-driven programming.

4 Likes

in the script all you need to do is find the script using parents for example script.Parent.Parent.Parent.Script and than put this .Disable = true so it can be disabled and .Disabled = false so it can be enable! (IF THATS WHAT U R LOOKING FOR!)

What’s the script output? I can try and help solve this, but what’s the current output?

Why are they two different scripts? You should put everything that is currently in the camera script, into the original script. Put it in the button2down function, then delete the empty camera script and delete the parts of the script that disabme and enable the camera script.

No errors and nothing in output :confused:

Script.Disable doesn’t really like to work for some reason, the wiki on it pretty much lies. Here is the wiki for what it should be doing: https://developer.roblox.com/en-us/api-reference/property/BaseScript/Disabled

Add some print() to see where the code fails.

  • are the “script.Parent.Camera.Disabled = …” lines executed?
  • have you checked if the “Camera” script enabled in the explorer while code is running?

Generally, I have no problem with setting the Disabled value to true/false.