Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why does my projectile dissappear early?

Asked by 5 years ago

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.

0
Does it destroy itself just before hitting the target because if so I had the same problem and it perplexed me too!!! OBenjOne 190 — 5y
0
Your problem is almost unbelievable to someone who has not already had the same problem. OBenjOne 190 — 5y
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. OBenjOne 190 — 5y
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 SWARMHOST77 12 — 5y
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. JayShepherdMD 147 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
    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.

Ad
Log in to vote
0
Answered by 4 years ago

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

Answer this question