Hello, I have created a bow and arrow recently and one of my scripts is not working right, Whenever I hit any NPC/Player the arrow will damage me and not the player I hit. I have 2 scripts a local script and a server script, the error is from the server script however. Here is the script
local tool = script.Parent
local handle = tool:WaitForChild('Handle')
local event = tool:WaitForChild('RemoteEvent')
local debounce = true
local cooldownTime = 0.5
local arrow = game.ReplicatedStorage.Arrow
event.OnServerEvent:Connect(function(player,pos)
local humanoid = tool.Parent:FindFirstChildWhichIsA('Humanoid')
if humanoid and humanoid.Health > 0 and debounce == true then
debounce = false
local newArrow = arrow:Clone()
newArrow.Parent = workspace
newArrow.CanCollide = false
newArrow.CFrame = CFrame.new(handle.Position,pos)
local velocity = Instance.new('BodyVelocity')
velocity.Parent = newArrow
velocity.Velocity = newArrow.CFrame.LookVector.Unit*75
velocity.MaxForce = Vector3.new('inf','inf','inf')
game.Debris:AddItem(velocity,25)
newArrow.Touched:Connect(function(hit)
local human = hit.Parent:FindFirstChildWhichIsA('Humanoid')
if human and humanoid.Health > 0 and human ~= humanoid then
humanoid:TakeDamage(55)
newArrow:Destroy()
elseif not human and hit.Cancollide == true and not hit:IsDescendantOf(humanoid.Parent) 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
newArrow.CanCollide = false
end
end)
game.Debris:AddItem(newArrow,10)
wait(cooldownTime)
debounce = true
end
end)
and if you need to know here is the local script
local tool = script.Parent
local handle = tool:WaitForChild('Handle')
local event = tool:WaitForChild('RemoteEvent')
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
tool.Activated:Connect(function()
event:FireServer(mouse.Hit.Position)
end)

1 comment
Dude, I was so confused at first cause I thought you were talking about line 9 and 10 then I realized you said HUMAN and were referring to that one LOL. Thank you alot, that helps me so much!