im having trouble with raycasting it works but only one time and by works i mean it shoots the arrow but it doesnt damage any humanoids in its path and then any more activations and it doesn’t do anything im trying to draw a ray to detect collisions since the arrow moves to faster then 60 fps
im activating this threw remote event in the tool to allow it to work serverside
local tool = script.Parent
local handle = tool:WaitForChild('Handle')
local event = tool:WaitForChild('Fire')
local debouce = true
local cooldownTime = 2
local arrow = game.ReplicatedStorage.Arrow
event.OnServerEvent:Connect(function(player,pos)
local humanoid = tool.Parent:FindFirstChildWhichIsA("Humanoid")
if humanoid and humanoid.Health > 0 and debouce == true then
debouce = false
local newarrow = arrow:Clone()
newarrow.Parent = workspace
newarrow.CFrame = CFrame.new(handle.Position,pos)
print(pos)
local rayOrigin = tool.Handle.Position --creating ray
local rayDirection = Vector3.new(pos)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {tool.Handle}--ray Params
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
local velocity = Instance.new('BodyVelocity')
velocity.Parent = newarrow
velocity.Velocity = newarrow.CFrame.LookVector.Unit*120
velocity.MaxForce = Vector3.new('inf','inf','inf')
newarrow.Touched:Connect(function(hit)
local human = hit.Parent:FindFirstChildWhichIsA('Humanoid')
if raycastResult then
local hitPart = raycastResult.Instance
if hitPart.Parent == human and hitPart.Transparency == 0 then -- if the ray hits humanoid
if human and human.Health > 0 and human ~= humanoid then
human:TakeDamage(5)
elseif not human and hit.CanCollide == true and not hit:IsDescendantOf(humanoid) and not hit:IsDescendantOf(tool) then
if velocity then
velocity:Destroy()
end
local weld = Instance.new('WeldConstraint')
weld.Parent = newarrow
weld.Part0 = newarrow
weld.Part1 = hit
newarrow.Massless = true
end
end
game.Debris:AddItem(newarrow,4)
wait(cooldownTime)
debouce = true
end
end)
end
end)