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 6 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.

01local function OnTouched(hit)
02    local Gamer = Players:GetPlayerFromCharacter(hit.Parent)
03    if not Gamer then
04        print("NPC")
05        local Bow = hit.Parent.ClassName
06        local animate = hit.Parent:FindFirstChild("Humanoid")
07        if animate and Gamer == nil then
08            hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - Damage
09            Arrow:Destroy()
10elseif Bow =="Tool" then
11else
12    Arrow:Destroy()
13    print(hit)
14end
15return 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 — 6y
0
Your problem is almost unbelievable to someone who has not already had the same problem. OBenjOne 190 — 6y
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 — 6y
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 — 6y
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 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
01    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
02 
03local humanoid = hit.Parent:FindFirstChild("Humanoid") -- Defines the humanoid object
04 
05if humanoid.Parent ~= Player.Character then -- If the humanoid's parent isn't the caster's character then
06 
07if not damaged then -- If not already damaged then
08 
09humanoid.Health = humanoid.Health - 20 -- Damages.
10 
11damaged = true -- Changes damaged to true so it won't damage anyone anymore.
12 
13game:GetService("Debris"):AddItem(ball,0.1)
14-- 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 5 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