Hi! I made an aim script for a raycast gun and for some unknown reason it randomly will phase in and out of aiming and sometimes not aim at all on certain guns. Some tools work, some don't.
Here is the localscript that handles all of it. (Mousebutton2 Up/Down and the while true are the important ones)
local aiming = false local cc = game.Workspace.CurrentCamera function Equip(mouse) local Player = game.Players.LocalPlayer local AmmoGui = script.Parent.AmmoGUI:Clone() idleAnim = script.Parent.Parent.Humanoid:LoadAnimation(script.Parent.Idle) fireAnim = script.Parent.Parent.Humanoid:LoadAnimation(script.Parent.Fire) AmmoGui.Parent = Player.PlayerGui AmmoGui.TextLabel1.LocalScript.Disabled = false AmmoGui.TextLabel2.LocalScript.Disabled = false mouse.Icon = "rbxasset://textures/GunCursor.png" idleAnim:Play() mouse.Button1Down:connect(function() print("Mouse pressed client!") if script.Parent.Ammo.Value > 0 and script.Parent.IsReloading.Value == false and script.Parent.IsFiring.Value == false then script.Parent.RemoteEvent:FireServer(mouse.Hit) fireAnim:Play() end end) mouse.Button2Down:connect(function() print("Mouse pressed client!") -- if (cc.focus.p - cc.CoordinateFrame.p).magnitude <= 1 then -- -- print("First person") -- repeat -- cc.FieldOfView = 20 -- wait(0.33) -- until (cc.focus.p - cc.CoordinateFrame.p).magnitude > 1 or aiming == false -- end aiming = true end) mouse.Button2Up:connect(function() print("Mouse pressed client!") aiming = false end) end function UnEquip(mouse) wait(0.5) local Player = game.Players.LocalPlayer Player.PlayerGui.AmmoGUI:Destroy() local cc = game.Workspace.CurrentCamera cc.FieldOfView = 80 aiming = false idleAnim:Stop() fireAnim:Stop() end script.Parent.Unequipped:Connect(UnEquip) script.Parent.Equipped:Connect(Equip) while true do wait(0.33) if (cc.focus.p - cc.CoordinateFrame.p).magnitude <= 1 then -- if aiming == true then cc.FieldOfView = 20 else cc.FieldOfView = 80 end else cc.FieldOfView = 80 end end