I'm making this bow that fires an arrow. Everything works fine however the arrow just disappears mid air, I have worked out this is because it somehow already knows where it's going to land so it just destroys itself.
local function OnTouched(hit) local Gamer = Players:GetPlayerFromCharacter(hit.Parent) if not Gamer then print("NPC") local Bow = hit.Parent.ClassName local animate = hit.Parent:FindFirstChild("Humanoid") if animate and Gamer == nil then hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - Damage Arrow:Destroy() elseif Bow =="Tool" then else Arrow:Destroy() print(hit) end return end
It's supposed to check Hit.Parent if it's a player if not then it checks if it has a Humanoid then does damage to the Humanoid but if not it checks if it hits the Tool/Bow if it's the bow that it has hit it continues until it hits a object like a wall or terrain the destroys itself. But for some reason it just destroys itself without needing to visually touching the object.
if hit.Parent or hit.Parent.Parent:FindFirstChild("Humanoid") then -- If the part's parent that it hit finds humanoid or part's parent parent (like sometimes you can hit accessory's handle and the handle is a child of the accessory so it's not the direct descendant of the character) finds humanoid then local humanoid = hit.Parent:FindFirstChild("Humanoid") -- Defines the humanoid object if humanoid.Parent ~= Player.Character then -- If the humanoid's parent isn't the caster's character then if not damaged then -- If not already damaged then humanoid.Health = humanoid.Health - 20 -- Damages. damaged = true -- Changes damaged to true so it won't damage anyone anymore. game:GetService("Debris"):AddItem(ball,0.1) -- Debris is like a server trash bin and the "additem" basically adds items to that trash that u define in the "( and )" so you put (ball, and the number here is the amount of time that needs to pass and then the object gets removed so the ball here gets removed after 0.1 seconds)
Example of a script that I made for a projectile, as you can see here I used, if not damaged and instead of destroying the arrow. I added it to Debris.
I have found a really nice projectile module script called fast casting Very reliable hit detection and uses projectiles
https://www.roblox.com/library/2009153526/FastCast-Example-Laser-Gun