game.ReplicatedStorage.RayCast.OnServerEvent:Connect(function(player,exit,mousehit) local debounce = false local ray = Ray.new(exit.Position, (mousehit.Position - exit.CFrame.Position).unit * 500) local part,position = workspace:FindPartOnRay(ray,player.Character,false,false) local bullet = Instance.new("Part",workspace) bullet.Material = Enum.Material.Neon bullet.BrickColor = BrickColor.new("Bright yellow") bullet.CanCollide = false bullet.Anchored = true bullet.Name = "Ak-47 Bullet" local distance = (exit.Position - position).magnitude bullet.Size = Vector3.new(-8.855, 0.025,distance) bullet.CFrame = CFrame.new(exit.Position, position) * CFrame.Angles(math.rad(math.random(0,5)),math.rad(math.random(0,9)),0) * CFrame.new(0,0,-distance / 2) bullet.Touched:Connect(function(hit) print(hit) end) end)
The Touched event does not detect the dummy or baseplate, it only detects the children of the tool and children of my player. How do i fix this?
Hello there!
I would suggest doing this on line 14.
if part then local humanoid = part:FindFirstChild('Humanoid') if humanoid then print("hit") end end
I don't suggest using .Touched
since it's very junky and unreliable. Raycast parts might do a better job at that, it's more reliable.
Happy coding!