So I was doing a custom magic attack, until I had to do the part where The attack does damage to what is in front, instead of using .OnTouched I decided to use Raycast, but here came the hard part, at least for me, well the fact is that i don’t know how to calculate the Ray destination, It needs to be in-front of the player’s head
My current code :
Remote.OnServerEvent:Connect(function(Player, Input, ...)
-- Player is the user who triggered the event, Input is the ability activated.
-- ... is a table that holds an infinite amount of arguments.
local Character = Player.Character
local RootPart = Character.HumanoidRootPart
local Humanoid = Character.Humanoid
local Params = {...}
if Input == 'BeamHit' then
local RCF = RootPart.CFrame
local Offset = {
-12.5,
12.5,
0
}
local Charge = Assets.Particles.Beamn.Charge.Attachment:Clone()
Charge.Parent = RootPart
Charge.Outline:Emit(1)
Charge.Gradient:Emit(1)
game:GetService('Debris'):AddItem(Charge, 0.5)
local origin = Character.Head.Position
local direction = Vector3.new(5,5,5) * 5
local raycastParamsz = RaycastParams.new()
raycastParamsz.FilterDescendantsInstances = {Character}
raycastParamsz.FilterType = Enum.RaycastFilterType.Blacklist
local rayResult = workspace:Raycast(origin, direction, raycastParamsz )
local hitPart = rayResult and rayResult.Instance
local hitPos = rayResult and rayResult.Position
if hitPart and hitPart.CanCollide then
print("Hello")
if hitPart.Parent:FindFirstChildWhichIsA("Humanoid") then
local hum = hitPart.Parent:WaitForChild("Humanoid")
hum:TakeDamage(5)
FXRemote:FireAllClients('BeamHit')
end
end
end
end)