so ive been making a sword combat system and i am using raycasting too detect collisions but i dont know a way too make the ray stay on the sword so i ended up just casting a bunch of rays every wait() but the problem is that its very inaccurate so is there a better way to do this?
script
for i = 1,8,1 do wait() local ray = Ray.new(script.Parent.Position, (script.Parent.CFrame.lookVector).unit*4) local hit, position = game.Workspace:FindPartOnRayWithIgnoreList(ray, {script.Parent, script.Parent.Parent.Head, script.Parent.Parent["Left Arm"], script.Parent.Parent["Left Leg"], script.Parent.Parent["Right Leg"], script.Parent.Parent.Torso, script.Parent.Parent.HumanoidRootPart}) if hit then if hit.Name == "Head" or hit.Name == "Torso" or hit.Name == "Right Arm" or hit.Name == "Left Arm" or hit.Name == "Left Leg" or hit.Name == "Right Leg" or hit.Name == "HumanoidRootPart" and hit.Parent.Hit.Value == false then game.ReplicatedStorage.Events.KIllerEvent:FireServer(hit) print(hit.Name .. " Was Hit!") hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 13 hit.Parent.Humanoid.MaxHealth = hit.Parent.Humanoid.MaxHealth - 4 wait(0.1) hit.Parent.Hit.Value = false else print(hit.Name .. " is not a valid part") end end end
btw im asking this question again cuz no one answered the first one