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
 

Gun script help

Previous Thread :: Next Thread 
yeox769 is not online. yeox769
Joined: 21 Jun 2010
Total Posts: 8907
16 Aug 2015 01:58 PM
I want the gun to set the player's health to 1 at the first hit, then to 0 at the second. Yet when I test it out, it just insta-kills the player.

Here's the script:

bullet.Touched:connect(function(hit)
if hit and hit.Parent and hit.Parent.Name ~= "Workspace" then
local h = hit.Parent:FindFirstChild'Humanoid'
if h.Health >1 then
h.Health = "1"
else
h.Health = "0"
end
end
end)



.:[Transmission end.]:.
Report Abuse
yeox769 is not online. yeox769
Joined: 21 Jun 2010
Total Posts: 8907
16 Aug 2015 01:59 PM
Or at least, the part of the script that's responsible for the health.


.:[Transmission end.]:.
Report Abuse
LongKillKreations is not online. LongKillKreations
Joined: 14 Feb 2014
Total Posts: 4502
16 Aug 2015 01:59 PM
Add a debounce. Also, raycasting is much better for this.
Report Abuse
71428 is not online. 71428
Joined: 06 Aug 2015
Total Posts: 339
16 Aug 2015 02:01 PM
if h.Health >1 then
h.Health = "1"
else
h.Health = "0"
end


What's up with the quotes. Remove them.

if h.Health >1 then
h.Health = 1
else
h.Health = 0
end
Report Abuse
yeox769 is not online. yeox769
Joined: 21 Jun 2010
Total Posts: 8907
16 Aug 2015 02:08 PM
Still not working. Here's the part of the script now:

local damageTaken = false
bullet.Touched:connect(function(hit)
if hit and hit.Parent and hit.Parent.Name ~= "Workspace" then
local h = hit.Parent:FindFirstChild'Humanoid'
if not damageTaken then
if h.Health >1 then
damageTaken = true
h.Health = "1"
damageTaken = false
else
damageTaken = true
h.Health = "0"
damageTaken = false
end
end
end
end)


.:[Transmission end.]:.
Report Abuse
yeox769 is not online. yeox769
Joined: 21 Jun 2010
Total Posts: 8907
16 Aug 2015 02:10 PM
@714

Makes no difference.


.:[Transmission end.]:.
Report Abuse
yeox769 is not online. yeox769
Joined: 21 Jun 2010
Total Posts: 8907
16 Aug 2015 02:18 PM
Anyone?


.:[Transmission end.]:.
Report Abuse
Kapitanovas is not online. Kapitanovas
Joined: 09 Sep 2012
Total Posts: 4216
16 Aug 2015 02:24 PM
what u mean "at second time"?
if u mean the 2nd bullet that hits the player then, it's not as easy as checking the health, u have to somehow mark the Humanoid to let other bullets know he/she has be hit

"My Life is going Good... but..."
Report Abuse
yeox769 is not online. yeox769
Joined: 21 Jun 2010
Total Posts: 8907
16 Aug 2015 02:35 PM
I made the script to check if the humanoid's health is at 1 or not, so it can set it to 0 or 1.


.:[Transmission end.]:.
Report Abuse
Kapitanovas is not online. Kapitanovas
Joined: 09 Sep 2012
Total Posts: 4216
16 Aug 2015 03:17 PM
well then it should work :P
"if Health > 1 then
Health = 1
else
Health = 0"
meaning that if the health is bigger than 1 i then it's set to 1 otherwise it's set to 0...
what's not working??? o.O

"My Life is going Good... but..."
Report Abuse
71428 is not online. 71428
Joined: 06 Aug 2015
Total Posts: 339
16 Aug 2015 05:27 PM
scriptEnabled = true
bullet.Touched:connect(function(hit)
if hit ~= nil then
if not scriptEnabled then
return
end

scriptEnabled = false
local h = hit.Parent:FindFirstChild("Humanoid")
if h.Health == 1 then
h.Health = 0
elseif h.Health > 1 then
h.Health = 1
wait(1)
end
scriptEnabled = true
end
end)

You need a debounce with waiting time because the function executes several times while the bullet travels through the player. Assuming it does. How fast is the bullet? You need to wait until it leaves the player's body. So you can find the magnitude of both the part it hit and the bullet and if it is a certain distance away it has left the body.
Report Abuse
WolfgangVonPrinz is not online. WolfgangVonPrinz
Joined: 24 Oct 2013
Total Posts: 4656
16 Aug 2015 05:49 PM
Use raycasting, this has been da thang since like 09'

Women are like fine wine, I can't get their tops off
Report Abuse
yeox769 is not online. yeox769
Joined: 21 Jun 2010
Total Posts: 8907
16 Aug 2015 10:22 PM
Thanks, 714!


.:[Transmission end.]:.
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