I made a simple bow script, when shot the arrow goes forward in a simple while loop and stop when hits something, but i noticed that the Touched does not fire when the arrow hits any part in the workspace, but still fires when the arrow hits players. I have no idea why is it happening. HELP?
local tool = script.Parent.Parent
local Necronomicon = require(game.ServerStorage.Necronomicon)
local Animator = game.ReplicatedStorage.Animator
local RemoteFunction = game.ReplicatedStorage.RemoteFunction
local character
local player
local canActivate = true
local cooldown = 2
local damage = 1
local brickdamage = 1
local Debris = game:GetService("Debris")
tool.AncestryChanged:Connect(function(ancestry)
if tool.Parent:FindFirstChild("Humanoid") then
character = tool.Parent
player = game.Players:GetPlayerFromCharacter(character)
end
end)
tool.Equipped:Connect(function(mouse)
if player then
Animator:FireClient(player, "HoldingBow")
end
end)
tool.Unequipped:Connect(function()
if player then
Animator:FireClient(player, "StopHoldingBow")
end
end)
local hitDebounce = true
local attacking = false
local putting = false
tool.Activated:Connect(function()
if canActivate == true and putting == false then
attacking = true
canActivate = false
local arrow = game.ServerStorage.Items.Sub.KoSSArrow:Clone()
local mousePos, mouseLV = RemoteFunction:InvokeClient(player, "mouse")
local mouse = CFrame.new(mousePos, mouseLV)
character.HumanoidRootPart.CFrame = CFrame.new(character.HumanoidRootPart.Position, mouse.Position)
Animator:FireClient(player, "FireBow")
script.Parent.AttackSound:Play()
arrow.CFrame = character.HumanoidRootPart.CFrame + character.RightHand.CFrame.LookVector * 1
arrow.CFrame = CFrame.new(arrow.Position, mouse.Position) -- lookAt
arrow.Parent = workspace
script.Parent.AttackSound:Play()
local hited = false
local touch = arrow.Touched:Connect(function(hit)
if hit.Parent ~= tool.Parent and hited == false
and hit.Name ~= "Handle" and hit.Parent ~= tool then
hited = true
print("hit")
if hit.Parent:FindFirstChild("Humanoid") or hit.Parent.Parent:FindFirstChild("Humanoid") then
script.Parent.Hit:Play()
Necronomicon.ToolDamage(hit, tool, 20, 1)
arrow.Anchored = false
arrow.Parent = hit
local weld = Instance.new("WeldConstraint", arrow)
weld.Part0 = arrow
weld.Part1 = hit
else
script.Parent.Arrow:Play()
end
arrow.Trail.Enabled = false
Debris:AddItem(arrow, 10)
end
end)
delay(cooldown, function()
hitDebounce = true
canActivate = true
attacking = false
end)
arrow.CFrame = CFrame.new(arrow.Position, mouse.Position) -- lookAt
arrow.Part.Position = arrow.Position
spawn(function()while hited == false do -- arrow model is anchored
arrow.CFrame = arrow.CFrame + arrow.CFrame.LookVector * 0.5 -- goes forward
wait()
end
touch:disconnect()
end)
end
end)

1 comment
try to make same script but for parts instead humanoids