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 to incorporate ammo into a gun?

Previous Thread :: Next Thread 
ShadowAley is not online. ShadowAley
Joined: 23 Jun 2010
Total Posts: 4823
02 Mar 2015 04:55 PM
I have the script made (it was tough enough as it was) but now I'm looking for a way to have ammo. The players ammo is unlimited, but the clip should be limited. How would I do that?


Heres the script:

local tool = script.Parent
local user
local isfiring

tool.Equipped:connect(function(mouse)
user = tool.Parent
mouse.Button1Down:connect(function()
isfiring = true
while isfiring do
-- make and do a hit test along the ray
tool.Handle.Fire:Play()
local ray = Ray.new(tool.Barrel6.CFrame.p, (mouse.Hit.p - tool.Barrel6.CFrame.p).unit*300)
local hit, position = game.Workspace:FindPartOnRay(ray, user)

-- do the damage to a humanoid
local humanoid = hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid:TakeDamage(5)
end

-- draw ray
local distance = (position - tool.Barrel6.CFrame.p).magnitude
local rayPart = Instance.new("Part", user)
rayPart.Name = "RayPart"
rayPart.BrickColor = BrickColor.new("Bright yellow")
rayPart.Transparency = .5
rayPart.Anchored = true
rayPart.CanCollide = false
rayPart.TopSurface = Enum.SurfaceType.Smooth
rayPart.BottomSurface = Enum.SurfaceType.Smooth
rayPart.formFactor = Enum.FormFactor.Custom
rayPart.Size = Vector3.new(0.2, 0.2, distance)
rayPart.CFrame = CFrame.new(position, tool.Barrel6.CFrame.p) * CFrame.new(0, 0, -distance/2)

game.Debris:AddItem(rayPart, 0.1)
wait(.1)
end
end)
mouse.Button1Up:connect(function()
isfiring = false
end)
end)
Report Abuse
ShadowAley is not online. ShadowAley
Joined: 23 Jun 2010
Total Posts: 4823
02 Mar 2015 05:09 PM
b
Report Abuse
Darkmist101 is not online. Darkmist101
Joined: 30 Jul 2010
Total Posts: 6208
02 Mar 2015 05:18 PM
http://wiki.roblox.com/index.php?title=How_to_Make_a_Raycasting_Lasergun

Did you really make it? If you did, clips wouldn't be a problem...

Basic flow chart (assuming you do know something):

-- User clicks
-- Checks if user is reloading
-- Shoot if not
-- Take away 1 bullet
-- if User has 0 bullets
-- Say they are reloading
-- Wait a few seconds
-- Set bullets back
-- Say they are not reloading

The alternative is just checking if it's zero but you should get it.
Report Abuse
Saldor010 is not online. Saldor010
Joined: 20 Sep 2010
Total Posts: 1035
02 Mar 2015 05:20 PM
Um, yeah, if you know enough to write a gun script, you know how to use some variables and if statements.
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