generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: How can I make this shield script better?

Previous Thread :: Next Thread 
Superwarrior360 is not online. Superwarrior360
Joined: 21 Feb 2013
Total Posts: 2703
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
Superwarrior360 is not online. Superwarrior360
Joined: 21 Feb 2013
Total Posts: 2703
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
toggytokyo is not online. toggytokyo
Joined: 09 Nov 2011
Total Posts: 50
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
Superwarrior360 is not online. Superwarrior360
Joined: 21 Feb 2013
Total Posts: 2703
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
toggytokyo is not online. toggytokyo
Joined: 09 Nov 2011
Total Posts: 50
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
Superwarrior360 is not online. Superwarrior360
Joined: 21 Feb 2013
Total Posts: 2703
13 Jul 2017 08:03 PM
That made no difference at all.
Report Abuse
Superwarrior360 is not online. Superwarrior360
Joined: 21 Feb 2013
Total Posts: 2703
25 Jul 2017 08:02 PM
bump
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image