hello i am having trouble with getting my damage function to work. Its my first time using raycasting to damage, so i was wondering if im doing something wrong
heres the code i made
--in the server script
gameModule.DealDamage(blade.Position, HRP.CFrame.LookVector, 10, char, 15)
--Damage Module
function module.DealDamage(origin: Vector3,direction: Vector3,rannge: number,char: Model, damage: number)
local rayParams = RaycastParams.new()
local hum = char.Humanoid
local plr = game.Players:GetPlayerFromCharacter(char)
rayParams.FilterType = Enum.RaycastFilterType.Blacklist
rayParams.FilterDescendantsInstances = {char}
local raycast = workspace:Raycast(origin, direction * rannge, rayParams)
print("working")
if raycast then
print("success")
local hit = raycast.Instance
local hitChar = hit:FindFirstAncestorOfClass("Model")
if hitChar then
local hitHum = hitChar:FindFirstChild("Humanoid")
local hitHRP = hitChar.HumanoidRootPart
local hitPlr = game.Players:GetPlayerFromCharacter(hitChar)
if hitHum then
if hitChar ~= char then
if char.Health ~= 0 or hitChar.Health ~= 0 and not folders.invinsibles:FindFirstChild(hitChar.Name.."Invinsible") and not folders.counters:FindFirstChild(hitChar.Name.."Counter") and not folders.stuns:FindFirstChild(plr.Name.."Stunned") then
hitHum:TakeDamage(damage)
module.Stun(hitChar, 12, 5, 1)
if hitHum.Health <= 0 then
print("Humanoid has died")
hum.Health = hum.MaxHealth
event:FireAllClients("Heal", char)
local gui = char.Head:FindFirstChild("GUI Attach").HealthAndStamina:FindFirstChild("Background").Health
gui:TweenSize(UDim2.new(1,0,1,0))
TS:Create(gui, TweenInfo.new(.5), {ImageColor3 = Color3.new(0.117647, 1, 0.145098)}):Play()
if hitPlr then
plr.leaderstats.Wins.Value = plr.leaderstats.Wins.Value + 1
end
end
end
if folders.counters:FindFirstChild(hitChar.Name.."Counter") then
module.Counter(char, hitChar)
end
end
end
end
else
warn("raycast failed")
end
end
heres a video too if its needed
im not sure why the raycast is erroring, help and feedback on my code would greatly be appriciated. thank you for your time