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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Breath Script

Previous Thread :: Next Thread 
OnlineOne is not online. OnlineOne
Joined: 14 Jul 2011
Total Posts: 1193
24 Jan 2016 03:36 PM
Hello. I'm trying to make a script that subtracts the player who touches the part's breath, and when they run out of breath, they start to lose health. Here's my script, which doesn't do anything it's supposed to.

local isColliding = false
local i = 0
local damage = 1
local maxBreath = 0
local minBreath = 100
local humanoid = script.Parent:FindFirstChild("Humanoid")
local playerGui = game.Players:FindFirstChild("PlayerGui")

--Changes colliding to true
function onCollided(onCollided)
isColliding = true
end

--Changes colliding to false
function onEnded(onEnded)
isColliding = false
end

--Subtract breath
while isColliding == true and i ~= minBreath and wait(0.1) do
i = i + 1
print("i = " .. i)
playerGui.BreathGui.Frame.TextLabel = playerGui.BreathGui.Frame.TextLabel.new("Breath = " .. i .. "/100")
end

--Add breath
while isColliding == false and i ~= maxBreath and wait(0.1) do
i = i - 1
print("i = " .. i)
playerGui.BreathGui.Frame.TextLabel = playerGui.BreathGui.Frame.TextLabel.new("Breath = " .. i .. "/100")
end

--Damage
while isColliding == true and i == minBreath and wait(0.1) do
humanoid.Health = humanoid.Health - damage
end

script.Parent.Touched:connect(onCollided)
script.Parent.TouchEnded:connect(onEnded)


- Online
Report Abuse
Klink45 is not online. Klink45
Joined: 06 Jun 2011
Total Posts: 26054
24 Jan 2016 03:38 PM
Output?

u sicko! http://www.roblox.com/u-sicko-item?id=328185093
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
24 Jan 2016 03:39 PM
Any output errors?


Report Abuse
OnlineOne is not online. OnlineOne
Joined: 14 Jul 2011
Total Posts: 1193
24 Jan 2016 03:39 PM
Yep.

Workspace.Base.Script:16: attempt to index upvalue 'playerGui' (a nil value)


- Online
Report Abuse
cgjnm is not online. cgjnm
Joined: 22 Dec 2011
Total Posts: 2347
24 Jan 2016 03:40 PM
PlayerGui
Report Abuse
OnlineOne is not online. OnlineOne
Joined: 14 Jul 2011
Total Posts: 1193
24 Jan 2016 03:40 PM
Forgot, here's my improved script.

local i = 0
local damage = 1
local maxBreath = 0
local minBreath = 100
local humanoid = script.Parent:FindFirstChild("Humanoid")
local playerGui = game.Players:FindFirstChild("PlayerGui")


--Changes colliding to true
function onCollided(onCollided)

--Subtract breath
while i ~= minBreath and wait(0.1) do
i = i + 1
print("i = " .. i)
playerGui.BreathGui.Frame.TextLabel = playerGui.BreathGui.Frame.TextLabel.new("Breath = " .. i .. "/100")
end

--Damage
while i == minBreath and wait(0.1) do
humanoid.Health = humanoid.Health - damage
end
end

--Changes colliding to false
function onEnded(onEnded)
--Add breath
while i ~= maxBreath and wait(0.1) do
i = i - 1
print("i = " .. i)
playerGui.BreathGui.Frame.TextLabel = playerGui.BreathGui.Frame.TextLabel.new("Breath = " .. i .. "/100")
end
end


script.Parent.Touched:connect(onCollided)
script.Parent.TouchEnded:connect(onEnded)


- Online
Report Abuse
cgjnm is not online. cgjnm
Joined: 22 Dec 2011
Total Posts: 2347
24 Jan 2016 03:41 PM
Oh I see...

local player = game.Players.LocalPlayer
local playerGui = player.PlayerGui
Report Abuse
cgjnm is not online. cgjnm
Joined: 22 Dec 2011
Total Posts: 2347
24 Jan 2016 03:41 PM
:local humanoid = script.Parent:FindFirstChild("Humanoid")
local playerGui = game.Players:FindFirstChild("PlayerGui")"

This will never work...
Report Abuse
OnlineOne is not online. OnlineOne
Joined: 14 Jul 2011
Total Posts: 1193
24 Jan 2016 03:42 PM
" Workspace.Base.Script:6: attempt to index local 'humanoid' (a nil value)"



Updated version doesn't work?

local humanoid = script.Parent:FindFirstChild("Humanoid")
local playerGui = humanoid:FindFirstChild("PlayerGui")


- Online
Report Abuse
Klink45 is not online. Klink45
Joined: 06 Jun 2011
Total Posts: 26054
24 Jan 2016 03:44 PM
Make sure this is inside the player's character or else the

local humanoid

line won't work.

u sicko! http://www.roblox.com/u-sicko-item?id=328185093
Report Abuse
OnlineOne is not online. OnlineOne
Joined: 14 Jul 2011
Total Posts: 1193
24 Jan 2016 03:47 PM
What is it that needs to be inside the player's character?

Also, here's my new script:

local i = 0
local damage = 1
local maxBreath = 0
local minBreath = 100
local player = game.Players.LocalPlayer
local playerGui = player.PlayerGui
local humanoid = script.Parent:FindFirstChild("Humanoid")


--Changes colliding to true
function onCollided(onCollided)

--Subtract breath
while i ~= minBreath and wait(0.1) do
i = i + 1
print("i = " .. i)
playerGui.BreathGui.Frame.TextLabel = playerGui.BreathGui.Frame.TextLabel.new("Breath = " .. i .. "/100")
end

--Damage
while i == minBreath and wait(0.1) do
humanoid.Health = humanoid.Health - damage
end
end

--Changes colliding to false
function onEnded(onEnded)
--Add breath
while i ~= maxBreath and wait(0.1) do
i = i - 1
print("i = " .. i)
playerGui.BreathGui.Frame.TextLabel = playerGui.BreathGui.Frame.TextLabel.new("Breath = " .. i .. "/100")
end
end


script.Parent.Touched:connect(onCollided)
script.Parent.TouchEnded:connect(onEnded)


- Online
Report Abuse
OnlineOne is not online. OnlineOne
Joined: 14 Jul 2011
Total Posts: 1193
24 Jan 2016 03:48 PM
"Workspace.Base.Script:6: attempt to index local 'player' (a nil value)"


- Online
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
24 Jan 2016 03:51 PM
...is this your code... or....?


Report Abuse
OnlineOne is not online. OnlineOne
Joined: 14 Jul 2011
Total Posts: 1193
24 Jan 2016 03:52 PM
It's my code.


- Online
Report Abuse
Klink45 is not online. Klink45
Joined: 06 Jun 2011
Total Posts: 26054
24 Jan 2016 03:53 PM
Honestly your script has way too many errors in it for me to even begin understanding and fixing it.



u sicko! http://www.roblox.com/u-sicko-item?id=328185093
Report Abuse
OnlineOne is not online. OnlineOne
Joined: 14 Jul 2011
Total Posts: 1193
24 Jan 2016 03:54 PM
k


- Online
Report Abuse
Klink45 is not online. Klink45
Joined: 06 Jun 2011
Total Posts: 26054
24 Jan 2016 03:55 PM
Though I will give you a hint: A player's PlayerGui is not stored in the Humanoid object, it is stored in the player.

u sicko! http://www.roblox.com/u-sicko-item?id=328185093
Report Abuse
cgjnm is not online. cgjnm
Joined: 22 Dec 2011
Total Posts: 2347
24 Jan 2016 03:55 PM
local script:

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local humanoid = char:WaitForChild'Humanoid'
local playerGui = player:FindFirstChild'PlayerGui'
Report Abuse
OnlineOne is not online. OnlineOne
Joined: 14 Jul 2011
Total Posts: 1193
24 Jan 2016 03:58 PM
The 'char' variable doesn't like the player variable.


- Online
Report Abuse
OnlineOne is not online. OnlineOne
Joined: 14 Jul 2011
Total Posts: 1193
24 Jan 2016 03:59 PM
And @Klink, I know that, which is why I'm referencing the LocalPlayer instead of the Humanoid obj..


- Online
Report Abuse
cgjnm is not online. cgjnm
Joined: 22 Dec 2011
Total Posts: 2347
24 Jan 2016 03:59 PM
The 'char' variable that I defined is the Character of the player (the player in the workspace)

It will work as long as it is in a local script.

What do you mean it doesn't like it?
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
24 Jan 2016 04:05 PM
I think we've got some copypastarino in our midst


Report Abuse
cgjnm is not online. cgjnm
Joined: 22 Dec 2011
Total Posts: 2347
24 Jan 2016 04:20 PM
^
Report Abuse
OnlineOne is not online. OnlineOne
Joined: 14 Jul 2011
Total Posts: 1193
24 Jan 2016 04:45 PM
Ah, now it's in a local script.


- Online
Report Abuse
OnlineOne is not online. OnlineOne
Joined: 14 Jul 2011
Total Posts: 1193
24 Jan 2016 04:46 PM
Still, the rest of the script doesn't work. No errors.


- Online
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