|
| 13 Jul 2017 07:13 PM |
local health = script.Parent.ShieldHealth.Value -- this is 10 function findNearestProjectile(pos) local list = game.Workspace:GetChildren() local dist = 50 local temp2 = nil for x = 1, #list do temp2 = list[x] if (temp2.className == "Part") and (temp2.Parent ~= script.Parent.Parent) then --print(temp2.Name) if temp2.Name == "Gun1" or temp2.Name == "Gun2" or temp2.Name == "Gun3" then if te###############=##c#######################hen if (temp2.Position - pos).magnitude < dist then if temp2.Name == "Gun1" or temp2.Name == "Gun2" then --WE'VE GOT A DEADLY MISSLE, BOYS! health = health - 1 script.Parent.ShieldHealth.Value = script.Parent.ShieldHealth.Value-1 end if temp2.Name == "Gun3" then --WE'VE GOT A DEADLY BULLET, BOYS! health = health - 0.5 script.Parent.ShieldHealth.Value = script.Parent.ShieldHealth.Value -0.5 end print(health) return temp2 end end end end end end --this is really good code, right??????
while health > 0 do wait(0.1) local target = findNearestProjectile(script.Parent.Main.Position) if target ~= nil then target:Destroy() end end if health <= 0 then script.Parent.ShieldPart.Transparency = 1 end
--------------------------- This script protects parts 50 studs around a main part. It works, but projectiles make it past the 50 stud mark before being deleted. How can I fix that? Right now, I've just made the rage 175, and this stops the bullets before they can cause harm. |
|
|
| Report Abuse |
|
|
|
| 13 Jul 2017 07:14 PM |
| If I shoot a stream of bullets at the shield, most get stopped, but a few make it slightly into the "protected" area. |
|
|
| Report Abuse |
|
|
|
| 13 Jul 2017 07:17 PM |
I think the issue is that this piece of code:
while health > 0 do wait(0.1) local target = findNearestProjectile(script.Parent.Main.Position) if target ~= nil then target:Destroy() end end
has the wait(0.1) in it. If a bullet goes through the shield in the "down time" that this wait creates, it wont be destroyed. You can try making it a shorter wait, but this may cause lag (maybe). |
|
|
| Report Abuse |
|
|
|
| 13 Jul 2017 07:19 PM |
| That's not the problem. I had the same idea, but when I changed it to wait(), the problem still persisted. Also, I forgot to mention this, but this issue is far more ubiquitous when I play from the site, compared to the play mode in studio. |
|
|
| Report Abuse |
|
|
|
| 13 Jul 2017 07:24 PM |
| Hmmmm.... I'm not sure then. It may just be that target:Destroy() takes some time to process. Try changing to to target:Remove() and see if it makes a difference. |
|
|
| Report Abuse |
|
|
|
| 13 Jul 2017 08:03 PM |
| That made no difference at all. |
|
|
| Report Abuse |
|
|
| |
|