I've got the hole position working but was wondering how to face the direction every time the FastCast ray hits.
-- Server
local rs = game:GetService('ReplicatedStorage)
local e_Impact = rs.Remotes.Events.ImpactEvent
function OnRayHit(cast, raycastResult, segmentVelocity, cosmeticBulletObject)
local hitPart = raycastResult.Instance
local hitPoint = raycastResult.Position
local normal = raycastResult.Normal
if hitPart ~= nil and hitPart.Parent ~= nil then
if hitPart.Name == 'Head' then
local humanoid = hitPart.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid:TakeDamage(Headshot)
end
elseif hitPart.Name ~= 'Head' then
local humanoid = hitPart.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid:TakeDamage(Bodyshot)
end
end
end
-- Right here. Tried to make it work the same way as ROBLOX's original RayCast, although is centers itself from said hitPart?
-- EDIT: dividing 'hitPoint' by 'normal' is so close but still not facing from where it came.
local holeCFrame = CFrame.new(hitPoint, hitPoint / normal)
e_Impact:FireAllClients(holeCFrame)
end
-- Client
local rs = game:GetService('ReplicatedStorage)
local e_Impact = rs.Remotes.Events.ImpactEvent
e_impact.OnClientEvent(function(hitpoint)
local impact = client:WaitForChild('Impact')
local hole = impact.BulletHole:Clone()
hole.Parent = workspace
hole.CFrame = hitpoint
hole.Impact:Play()
end)
