Yo, I’m new to this raycast thingy, So I got this from a forum post a long time ago ( I can’t find it )
LocalScript: ( Not full Script )
local Players = game:GetService("Players")
local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local Mouse = Players.LocalPlayer:GetMouse()
local Character = Players.LocalPlayer.Character
local Camera = game.Workspace.CurrentCamera
local function RaycastMouse()
local Blacklist = {}
-- ignore self
for i, Baseparts in pairs(Character:GetDescendants()) do
if Baseparts:IsA("BasePart") then
table.insert(Blacklist, Baseparts)
end
end
-- ignore parts with no collisions
for i, Baseparts in pairs(game.Workspace:GetDescendants()) do
if Baseparts:IsA("BasePart") then
if Baseparts.CanCollide == false then
table.insert(Blacklist, Baseparts)
end
end
end
-- Ignore teammates
for i, Player in pairs(Players:GetPlayers()) do
if Player.Team == Players.LocalPlayer.Team and Player.Character then
for i, Baseparts in pairs(Player.Character:GetDescendants()) do
if Baseparts:IsA("BasePart") then
table.insert(Blacklist, Baseparts)
end
end
end
end
local RaycastParameters = RaycastParams.new()
RaycastParameters.FilterDescendantsInstances = Blacklist
RaycastParameters.FilterType = Enum.RaycastFilterType.Blacklist
local UnitRay = Camera:ScreenPointToRay(Mouse.X, Mouse.Y)
return workspace:Raycast(UnitRay.Origin, UnitRay.Direction * 100, RaycastParameters)
end
It works, but the raycast is going right through walls
so I changed UnitRay.Origin
to the ShootPos on the handle
return workspace:Raycast(Handle.ShootPos.Position, UnitRay.Direction * 100, RaycastParameters)
It works but the bullets go in the wrong directions
so I searched through the DevForum and got nothing
ㅤ
ㅤ
ㅤ
help