Hello! I have a flying tool in my game which I will post the script of. While walking, players can pass right through objects as intended, but when using the fly tool, they knock right into them as if CanCollide is checked!
Is there anything I can put in the script to make players able to properly communicate with these objects that are non-collidable? Note: not all objects, just the ones set to non-collidable!
Thank you so much!
Here is the script for the flying tool:
local FLY_SPEED = 30 --studs/second local BODYOBJECT_NAME_PREFIX = "FLY_TOOL_" local MAX_FORCE = Vector3.new(1, 1, 1) * math.huge --infinite force on each axis local MAX_TORQUE = Vector3.new(1, 1, 1) * math.huge local self = script.Parent local player = game.Players.LocalPlayer local mouse = player:GetMouse() local held = false local character, human, torso, bv, bg, dir --variables to be used later mouse.Button1Down:connect(function() if bv then held = true while held do bv.velocity = FLY_SPEED * (mouse.Hit.p - root.Position).unit bg.cframe = CFrame.new(root.Position, mouse.Hit.p) * CFrame.Angles(-math.pi/2, 0, 0) wait() end bv.velocity = Vector3.new() bg.cframe = Workspace.CurrentCamera.CoordinateFrame end end) mouse.Button1Up:connect(function() held = false end) self.Selected:connect(function() character = player.Character; if not character then return end human = character:FindFirstChild("Humanoid"); if not human then return end root = character:FindFirstChild("HumanoidRootPart"); if not root then return end bv = Instance.new("BodyVelocity", root) bv.Name = BODYOBJECT_NAME_PREFIX .. "BodyVelocity" bv.maxForce = MAX_FORCE bg = Instance.new("BodyGyro", root) bg.Name = BODYOBJECT_NAME_PREFIX .. "BodyGyro" bg.maxTorque = MAX_TORQUE bg.cframe = root.CFrame human.PlatformStand = true end) self.Deselected:connect(function() held = false if human then human.PlatformStand = false end if bv then bv:Destroy() end if bg then bg:Destroy() end end)
This happens because of your mouse.Hit.p
The only way to fix this is set the mouse.TargetFilter to an instance. All descendants and the instance itself will then be ignored.
mouse.TargetFilter = game.Workspace
Would make the mouse ignore every part in the workspace.