Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is Raycast hitting player?

Asked by
Jec0be 11
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?


local gun = script.Parent local fireEvent = gun.FireEvent local FastCast = require(gun.FastCastRedux) local firePoint = gun.Handle.FirePoint local bulletsFolder = workspace:FindFirstChild("BulletFolder") or Instance.new("Folder", workspace) bulletsFolder.Name = "BulletFolder" local bulletsTemplate = Instance.new("Part") bulletsTemplate.Anchored = true bulletsTemplate.CanCollide = false bulletsTemplate.Shape = "Ball" bulletsTemplate.Size = Vector3.new(1, 1, 1) bulletsTemplate.Material = Enum.Material.Metal FastCast.VisualizeCasts = false local caster = FastCast.new() local castParams = RaycastParams.new() local castParams = RaycastParams.new() castParams.FilterType = Enum.RaycastFilterType.Blacklist castParams.IgnoreWater = true castParams.FilterDescendantsInstances = {gun.Parent, bulletsFolder, bulletsTemplate, gun} local castBehavior = FastCast.newBehavior() castBehavior.RayCastParams = castParams castBehavior.Acceleration = Vector3.new(0, -workspace.Gravity, 0) castBehavior.AutoIgnoreContainer = false castBehavior.CosmeticBulletContainer = bulletsFolder castBehavior.CosmeticBulletTemplate = bulletsTemplate local function onEquipped() castParams.FilterDescendantsInstances = {gun.Parent:FindFirstChildWhichIsA("Part") , bulletsFolder, bulletsTemplate, gun} end local function onLengthChanged(cast, lastPoint, direction, length, velocity, bullet) if bullet then local bulletLength = bullet.Size.Z/2 local offset = CFrame.new(0, 0, -(length - bulletLength)) bullet.CFrame = CFrame.lookAt(lastPoint, lastPoint + direction):ToWorldSpace(offset) end end local function onRayHit(cast, result, velocity, bullet) local hit = result.Instance local character = hit:FindFirstAncestorWhichIsA("Model") if character and character:FindFirstChild("Humanoid") then if not character:FindFirstChild("Gun") then character.Humanoid:TakeDamage(25) end if hit.Parent ~= gun.Parent and hit.Parent ~= gun then print(hit.Parent) elseif hit.Parent == gun.Parent or hit.Parent == gun then warn(hit.Parent, "shot themself due to a bug...") end end game:GetService("Debris"):AddItem(bullet, 5) end local function fire(player, mousePosition) local origin = firePoint.WorldPosition local direction = (mousePosition - origin).Unit local velocity = 69426969 caster:Fire(origin, direction, velocity, castBehavior) gun.Handle.GunShot.Playing = true end fireEvent.OnServerEvent:Connect(fire) gun.Equipped:Connect(onEquipped) caster.LengthChanged:Connect(onLengthChanged) caster.RayHit:Connect(onRayHit)

here's the script

Answer this question