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
|
  |
| 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
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
| |
|
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
|
  |
| Joined: 22 Dec 2011 |
| Total Posts: 2347 |
|
| |
|
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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 24 Jan 2016 03:51 PM |
...is this your code... or....?
|
|
|
| Report Abuse |
|
|
OnlineOne
|
  |
| Joined: 14 Jul 2011 |
| Total Posts: 1193 |
|
| |
|
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
|
  |
| Joined: 14 Jul 2011 |
| Total Posts: 1193 |
|
| |
|
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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 22 Dec 2011 |
| Total Posts: 2347 |
|
| |
|
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
|
  |
| 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 |
|
|