Why is Raycast hitting player?
Asked by
3 years ago Edited 3 years ago
I made a roblox raycast script and ti damages the person holding the tool even though it is blacklisted. What did I do wrong?
01 | local gun = script.Parent |
02 | local fireEvent = gun.FireEvent |
03 | local FastCast = require(gun.FastCastRedux) |
04 | local firePoint = gun.Handle.FirePoint |
06 | local bulletsFolder = workspace:FindFirstChild( "BulletFolder" ) or Instance.new( "Folder" , workspace) |
07 | bulletsFolder.Name = "BulletFolder" |
09 | local bulletsTemplate = Instance.new( "Part" ) |
10 | bulletsTemplate.Anchored = true |
11 | bulletsTemplate.CanCollide = false |
12 | bulletsTemplate.Shape = "Ball" |
13 | bulletsTemplate.Size = Vector 3. new( 1 , 1 , 1 ) |
14 | bulletsTemplate.Material = Enum.Material.Metal |
16 | FastCast.VisualizeCasts = false |
18 | local caster = FastCast.new() |
20 | local castParams = RaycastParams.new() |
21 | local castParams = RaycastParams.new() |
23 | castParams.FilterType = Enum.RaycastFilterType.Blacklist |
25 | castParams.IgnoreWater = true |
26 | castParams.FilterDescendantsInstances = { gun.Parent, bulletsFolder, bulletsTemplate, gun } |
28 | local castBehavior = FastCast.newBehavior() |
29 | castBehavior.RayCastParams = castParams |
30 | castBehavior.Acceleration = Vector 3. new( 0 , -workspace.Gravity, 0 ) |
31 | castBehavior.AutoIgnoreContainer = false |
32 | castBehavior.CosmeticBulletContainer = bulletsFolder |
33 | castBehavior.CosmeticBulletTemplate = bulletsTemplate |
35 | local function onEquipped() |
36 | castParams.FilterDescendantsInstances = { gun.Parent:FindFirstChildWhichIsA( "Part" ) , bulletsFolder, bulletsTemplate, gun } |
39 | local function onLengthChanged(cast, lastPoint, direction, length, velocity, bullet) |
41 | local bulletLength = bullet.Size.Z/ 2 |
42 | local offset = CFrame.new( 0 , 0 , -(length - bulletLength)) |
43 | bullet.CFrame = CFrame.lookAt(lastPoint, lastPoint + direction):ToWorldSpace(offset) |
47 | local function onRayHit(cast, result, velocity, bullet) |
48 | local hit = result.Instance |
50 | local character = hit:FindFirstAncestorWhichIsA( "Model" ) |
52 | if character and character:FindFirstChild( "Humanoid" ) then |
53 | if not character:FindFirstChild( "Gun" ) then |
54 | character.Humanoid:TakeDamage( 25 ) |
56 | if hit.Parent ~ = gun.Parent and hit.Parent ~ = gun then |
58 | elseif hit.Parent = = gun.Parent or hit.Parent = = gun then |
59 | warn(hit.Parent, "shot themself due to a bug..." ) |
63 | game:GetService( "Debris" ):AddItem(bullet, 5 ) |
66 | local function fire(player, mousePosition) |
67 | local origin = firePoint.WorldPosition |
68 | local direction = (mousePosition - origin).Unit |
69 | local velocity = 69426969 |
71 | caster:Fire(origin, direction, velocity, castBehavior) |
72 | gun.Handle.GunShot.Playing = true |
76 | fireEvent.OnServerEvent:Connect(fire) |
78 | gun.Equipped:Connect(onEquipped) |
80 | caster.LengthChanged:Connect(onLengthChanged) |
81 | caster.RayHit:Connect(onRayHit) |
here's the script