Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does my projectile dissappear early?

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.

5 comments

0

Does it destroy itself just before hitting the target because if so I had the same problem and it perplexed me too!!!

0

Your problem is almost unbelievable to someone who has not already had the same problem.

0

I think it may have something to do with server-client lag? I found a way around it with rays but I would like to see this mystery solved.

0

Mine also dissappear befor hitting the target however when hitting a NPC or player they disspear early but the NPC or player gets hurt. I am inclined to think it could be a server client lag problem

0

hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - Damage, minus damage I'm assuming means without damage so, if your characters health is on 100% then it's gonna destroy.

2 answers

    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.

This discussion is preserved as it was. New answers, comments, and votes are closed.