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
 

Re: Making a simple gun...

Previous Thread :: Next Thread 
TanCalypso123 is not online. TanCalypso123
Joined: 26 Jun 2012
Total Posts: 14
26 May 2014 06:02 AM
I'm trying to make a very simple gun. The bullet doesn't travel through the air. It just appears where it is going to be so that it is much easier for me. But I get an error on line 18. Here is the exact text from the output:
07:00:15.070 - Script 'Players.Player1.Backpack.HopperBinGunTest.MainTest', Line 18 - global onClicked
07:00:15.071 - Script 'Players.Player1.Backpack.HopperBinGunTest.MainTest', Line 57
07:00:15.071 - Stack End
07:00:15.073 - Disconnected event because of exception

Here is my LOCALSCRIPT:

local hop = script.Parent
local Player = game.Players.LocalPlayer
local DefaultName = "HopperBinGunTest"
local Damage = 25
Object = "Humanoid" --If you want this to be a zombie killing gun only set this to Zombie
TeamColors = {"None"} --Make sure there is one item in the table. I am not sure what would happen if nothing was in it
local Ready = true

function onClicked(mouse)
if Ready == true then
Ready = false
print("Hopperbin clicked")
hop.Name = "Shooting"
script.Parent.ShotSound:Play()
Bullet = Instance.new("Part", Workspace)
Bullet.Anchored = true
Bullet.CanCollide = false
Bullet.Position = mouse.Target --[[The error is right here. I know mouse.Target is an object. I learned about it on the wiki]]
Bullet.Name = "Projectile"
Bullet.BottomSurface = "Smooth"
Bullet.TopSurface = "Smooth"
Bullet.Size = Vector3.new(2, 2, 2)
Bullet.FormFactor = "Symmetric"
Bullet.Shape = "Ball"
Bullet.BrickColor = Player.TeamColor
hop.Name = "Coloring Bullet to "..Bullet.BrickColor
hop.Name = "Giving damage"
Bullet.Touched:connect(function(hit)
if hit.Parent:FindFirstChild(Object) then
hithuman = hit.Parent:FindFirstChild(Object)
for i,v in pairs(TeamColors) do
if game.Players:FindFirstChild(hit.Parent.Name) then
hitplayer = game.Players:FindFirstChild(hit.Parent.Name)
if hitplayer.TeamColor == v and hitplayer.Neutral == false then
print("Player is on team. DO NOT TEAMKILL!")
hop.Name = "Player is on your team"
elseif hitplayer.TeamColor ~= v or hitplayer.Neutral == true then
hithuman:TakeDamage(Damage)
hop.Name = "Giving Damage..."
end
end
end
end
end)
game.Debris:AddItem(Bullet, 5)
hop.Name = "Cocking..."
script.Parent.CockSound:Play()
wait(2)
Ready = true
hop.Name = "Selected"
end
end

hop.Selected:connect(function(mouse)
print("HopperBin selected")
hop.Name = "Selected"
mouse.Button1Down:connect(function() onClicked(mouse) end)
end)

hop.Deselected:connect(function(mouse)
print("HopperBin deselected")
hop.Name = DefaultName
end)

Please help! I'm been trying to make guns ever since I've learned how to script!
Report Abuse
lightpower26 is not online. lightpower26
Joined: 26 Apr 2012
Total Posts: 1046
26 May 2014 06:11 AM
Bump
Report Abuse
TanCalypso123 is not online. TanCalypso123
Joined: 26 Jun 2012
Total Posts: 14
26 May 2014 06:17 AM
Forgot a bit of the output.

This appeared at the top:
07:16:22.711 - Players.Player1.Backpack.HopperBinGunTest.MainTest:18: bad argument #3 to 'Position' (Vector3 expected, got userdata)

How do I get a vector3 value out of mouse.Target? Do I use mouse.Position or mouse.Target.Position or something else??
Report Abuse
Ceoh is not online. Ceoh
Joined: 17 Nov 2013
Total Posts: 152
26 May 2014 06:24 AM
mouse.Target.Position

However that is assuming that the mouse.Target is a Part object, so you need to some analysis and put some If statements about the mouse.Target before you do anything.
Report Abuse
TanCalypso123 is not online. TanCalypso123
Joined: 26 Jun 2012
Total Posts: 14
26 May 2014 06:26 AM
How would you define the mouse's position? Use mouse.X and mouse.Y?
Report Abuse
TanCalypso123 is not online. TanCalypso123
Joined: 26 Jun 2012
Total Posts: 14
26 May 2014 07:02 AM
Oh I got it! I just got one problem...When I added ammo the thing will only shoot once and there is no error in the output. All the prints print.

local hop = script.Parent
local Player = game.Players.LocalPlayer
local DefaultName = "HopperBinGunTest"
local Damage = 25
local HeadShotDamage = 50
Object = "Humanoid" --If you want this to be a zombie killing gun only set this to Zombie
local Ready = true
A = script.Parent:WaitForChild("Ammo")
SA = script.Parent:WaitForChild("StoredAmmo")
MA = script.Parent:WaitForChild("MaxAmmo")

function onClicked(mouse)
if Ready == true and A.Value <= MA.Value then
Ready = false
A.Value = A.Value - 1
print("Hopperbin clicked")
script.Parent.ShotSound:Play()
if mouse.Target.Parent:FindFirstChild(Object) then
hitpart = mouse.Target
hithuman = mouse.Target.Parent:FindFirstChild(Object)
hitplayer = game.Players:FindFirstChild(hithuman.Parent.Name)
if hitplayer.TeamColor ~= Player.TeamColor or hitplayer.Neutral == true then
if hitpart.Name == "Head" then
hithuman:TakeDamage(HeadShotDamage)
else
hithuman:TakeDamage(Damage)
end
end
end
hop.Name = "HopperGun "..A.Value.."/"..MA.Value.."/"..SA.Value
if A.Value == 0 and SA.Value > 0 then
hop.Name = "HopperGun Reloading..."
script.Parent.CockSound:Play()
wait(1.5)
SA.Value = SA.Value - MA.Value
A.Value = MA.Value
Ready = true
hop.Name = "HopperGun "..A.Value.."/"..MA.Value.."/"..SA.Value
end
end
end

hop.Selected:connect(function(mouse)
print("HopperBin selected")
hop.Name = "HopperGun "..A.Value.."/"..MA.Value.."/"..SA.Value
mouse.Button1Down:connect(function() onClicked(mouse) end)
end)

hop.Deselected:connect(function(mouse)
print("HopperBin deselected")
hop.Name = DefaultName
end)

Report Abuse
Ceoh is not online. Ceoh
Joined: 17 Nov 2013
Total Posts: 152
26 May 2014 07:14 AM
if Ready == true and A.Value <= MA.Value then

What are your A.Value and MA.Value?
Report Abuse
ZirutoHellfire is not online. ZirutoHellfire
Joined: 16 Aug 2012
Total Posts: 4647
26 May 2014 07:20 AM
I assume A is Ammo and MA is Max Ammo :3

No life, for life.
Report Abuse
Ceoh is not online. Ceoh
Joined: 17 Nov 2013
Total Posts: 152
26 May 2014 07:26 AM
No I meant what are the actual numbers you start with?
Report Abuse
TanCalypso123 is not online. TanCalypso123
Joined: 26 Jun 2012
Total Posts: 14
26 May 2014 11:13 AM
30 and 30. MaxAmmo is 150 I think
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