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 » Scripting Helpers
Home Search
 

Wait(5) before shooting again wont work?

Previous Thread :: Next Thread 
bluebird1287 is not online. bluebird1287
Joined: 16 Jun 2011
Total Posts: 4202
17 Jul 2014 01:38 PM
bin = script.Parent
dist = 80

function getHumans()
for _, v in pairs(game.Players:GetChildren()) do
if v.Character ~= nil and v.Character:FindFirstChild("Torso") ~= nil and v.Character:FindFirstChild("Humanoid") ~= nil and v.Character.Humanoid.Health > 0 then
if (v.Character.Torso.Position - script.Parent.Shooter.Position).magnitude <= 80 then
return v.Character.Torso
end
end
end
return nil
end

function aim(targ)
local dir = targ.Position - script.Parent.Barrel.Position
dir = computeDirection(dir)
local mag = (targ.Position - script.Parent.Barrel.Position).magnitude
local spawnPos = script.Parent.Barrel.Position
local pos = spawnPos + (dir * (math.ceil(mag)/2))
bin.Barrel.BodyGyro.cframe = CFrame.new(pos, pos + dir)
local look = script.Parent.Shooter.CFrame.lookVector
local p = Instance.new("Part")
p.formFactor = "Symmetric"
p.Size = Vector3.new(1,1,1)
p.TopSurface = "Smooth"
p.Shape = "Ball"
p.BottomSurface = "Smooth"
p.Name = "Bullet"
p.BrickColor = BrickColor.new(26)
pMesh = Instance.new("SpecialMesh")
pMesh.MeshId = "http://www.roblox.com/asset/?id=101160425"
pMesh.TextureId = "http://www.roblox.com/asset/?id=101159976"
pMesh.Scale = Vector3.new(1, 1, 1)
pMesh.Parent = p
p.CFrame = script.Parent.Shooter.CFrame + (1.5*look)
local b = Instance.new("BodyVelocity")
b.velocity = (50*look)
b.Parent = p
p.Parent = workspace
local sc = script.Damage:clone()
sc.Disabled = false
sc.Parent = p
end


function computeDirection(vec)
local lenSquared = vec.magnitude * vec.magnitude
local invSqrt = 1 / math.sqrt(lenSquared)
return Vector3.new(vec.x * invSqrt, vec.y * invSqrt, vec.z * invSqrt)
end

while true do
wait(0.1)
local target = getHumans()
if target ~= nil then
aim(target)
end
end

--where do i put wait(5)?
Report Abuse
bluebird1287 is not online. bluebird1287
Joined: 16 Jun 2011
Total Posts: 4202
17 Jul 2014 01:39 PM
bump
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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