so i am making a gun that using raycasting but it not working as it supposed to do
it hit a wall that not even in it way
the script
local tool = script.Parent
local Player = game.Players.LocalPlayer
local PlayerGui = Player.PlayerGui
local Character = Player.Character or Player.CharacterAdded:Wait()
local inputService = game:GetService("UserInputService")
local Mouse = Player:GetMouse()
local event = game.ReplicatedStorage:WaitForChild("MonkeyTime")
local hit2 = game.Workspace:WaitForChild("hit")
local sounnd = tool:WaitForChild("Sound")
local cooldown = false
local raycastingParms = RaycastParams.new()
local currentcamera = workspace.CurrentCamera
raycastingParms.FilterDescendantsInstances = {tool:GetChildren(),game.Workspace:WaitForChild("Bananas"),Character,hit2}
raycastingParms.FilterType = Enum.RaycastFilterType.Exclude
raycastingParms.IgnoreWater =true
tool.Activated:Connect(function()
local StarterRay = tool.Handle:FindFirstChild("RayStart")
local Direction = (Mouse.Hit.Position - StarterRay.Position).Unit * 800
local raycasting = game.Workspace:Raycast(StarterRay.Position,Direction,raycastingParms)
if raycasting then
if raycasting.Instance then
hit2.Position = StarterRay.Position + (Mouse.Hit.Position - StarterRay.Position)
local Humanoid = raycasting.Instance.Parent.Parent:FindFirstChild("Humanoid") or raycasting.Instance.Parent:FindFirstChild("Humanoid")
if Humanoid and not cooldown then
sounnd:Play()
event:FireServer(Humanoid.Parent,raycasting.Position,tool.Handle)
cooldown = true
task.wait(2)
cooldown = false
else
print(raycasting.Instance)
local raycastingColor = raycasting.Instance.Color
if raycasting.Instance.Color ~= Color3.new(1, 0, 0.0156863) then
raycasting.Instance.Color = Color3.new(1, 0, 0.0156863)
task.wait(0.5)
raycasting.Instance.Color = raycastingColor
end
end
else
print('no object was found')
end
else
print("no result :<")
end
end)
here a video to make it clear