-
What do you want to achieve? I use fastcast for my raycasts and want my gun system to hit every targets.
-
What is the issue? Sometimes, the raycast just goes through the target character, as you can see on this picture:
-
What solutions have you tried so far? I tried to fix it myself and looked on forums but i didn’t found anything.
Also this is the ray hit part of the code
function onRayHit(cast, result, velocity, bullet)
local hit = result.Instance
local character = hit:FindFirstAncestorWhichIsA("Model")
print("Damage 1")
print(hit)
print(character)
print(character:FindFirstChildWhichIsA("Humanoid"))
if character then
if character:FindFirstChild("Humanoid") then
print("Damage 2")
local originPlayer = cast.UserData.OriginPlayer
local targetPlayer = Players:GetPlayerFromCharacter(character)
if targetPlayer.Team ~= originPlayer.Team then
print("Damage 3")
if originPlayer.Team == Teams.Raiders then
print("Damage 4")
if targetPlayer.Team == Teams.Security then
print("Damage 5")
if hit.Name == "Head" then
print("Damage 6")
character.Humanoid:TakeDamage(20)
else
print("Damage 7")
character.Humanoid:TakeDamage(15)
end
else
print("Damage 8")
if targetPlayer.InKillZone.Value == true then
print("Damage 9")
if hit.Name == "Head" then
print("Damage 10")
character.Humanoid:TakeDamage(20)
else
print("Damage 10")
character.Humanoid:TakeDamage(15)
end
end
end
end
print("Damage 11")
if originPlayer.Team == Teams.Security then
print("Damage 12")
if targetPlayer.Team == Teams.Raiders then
print("Damage 13")
if hit.Name == "Head" then
print("Damage 14")
character.Humanoid:TakeDamage(30)
else
print("Damage 15")
character.Humanoid:TakeDamage(15)
end
else
print("Damage 16")
if targetPlayer.InKillZone.Value == true then
print("Damage 17")
if hit.Name == "Head" then
print("Damage 18")
character.Humanoid:TakeDamage(30)
else
print("Damage 19")
character.Humanoid:TakeDamage(15)
end
end
end
end
end
end
end
if hit:IsA("Part") and hit.CanCollide == true and hit.Transparency < 0.7 then
local hitPartClone = ServerStorage.BulletHitPart:Clone()
hitPartClone.Parent = hit
hitPartClone.Position = result.Position
--hitPartClone.CFrame = CFrame.new(result.Position, result.Position + result.Normal)
hitPartClone.CFrame = CFrame.lookAt(result.Position, result.Position + result.Normal)
hitPartClone.BulletSound:Play()
hitPartClone.Particles.Smoke.Color = ColorSequence.new(hit.Color)
hitPartClone.Particles.Smoke:Emit(20)
if hitPartClone:FindFirstChild(hit.Material.Name) then
print(hit.Material.Name)
hitPartClone[hit.Material.Name]:Play()
end
if hitPartClone.Particles:FindFirstChild(hit.Material.Name) then
print(hit.Material.Name)
print(hitPartClone.Particles[hit.Material.Name])
if hit.Material.Name ~= "Metal" then
hitPartClone.Particles[hit.Material.Name].Color = ColorSequence.new(hit.Color)
end
hitPartClone.Particles[hit.Material.Name]:Emit(30)
end
Debris:AddItem(hitPartClone, 10)
end
end
What do the prints output? Are they all going through?
It stops at Damage1, the print(hit) outputs the wall behind, character outputs workspace and character:FindFirstChildWhichIsA(“Humanoid”) outputs nil