IceOrb
|
  |
| Joined: 02 May 2010 |
| Total Posts: 1206 |
|
|
| 09 May 2013 01:18 PM |
I wanted to adapt a vehicle I made so that it runs on "battery" similar to that off a WIJ weapon where you touch to recharge to full 100 battery. It will start off with 100 battery, and as you continuously drive about, the battery depletes. How would I do this? like to make it deplete etc? Not too sure. Also once it has reached 0 battery, the vehicle doesn't move any more; maybe changing the value of the throttle to 0 or something. I also wanted to link this into a GUI, but I can do that I think. Just wondering how to make it deplete and stop the car? |
|
|
| Report Abuse |
|
|
IceOrb
|
  |
| Joined: 02 May 2010 |
| Total Posts: 1206 |
|
|
| 09 May 2013 01:36 PM |
My explanation is quite confusing haha x3 Basically I want the textlabel number to deplete every time the vehicle moves. Once the text value hits = "0" then the car stops moving unless you drive into a charge point which I'll sort out. |
|
|
| Report Abuse |
|
|
| |
|
IceOrb
|
  |
| Joined: 02 May 2010 |
| Total Posts: 1206 |
|
| |
|
|
| 09 May 2013 02:32 PM |
while wait() do Battery = Battery - 1 wait(5) end
This is an example. |
|
|
| Report Abuse |
|
|
IceOrb
|
  |
| Joined: 02 May 2010 |
| Total Posts: 1206 |
|
|
| 09 May 2013 02:47 PM |
Oh but how would that minus from the text label text itself? :p Sorry really confused :c |
|
|
| Report Abuse |
|
|
|
| 09 May 2013 03:01 PM |
The trick would be to basically have the text label watch a value. Out an intValue in somewhere
This script should go into the text label BatteryValue = (You're Value) TextLabel = script.Parent
function onChanged() TextLabel.Text = Battery.Value end
Battery.Changed:connect(onChanged) |
|
|
| Report Abuse |
|
|
IceOrb
|
  |
| Joined: 02 May 2010 |
| Total Posts: 1206 |
|
|
| 09 May 2013 03:12 PM |
Oh true, so an intValue will need to be placed into the text label. So the IntValue is the actual figure changing rather than the text label! |
|
|
| Report Abuse |
|
|
IceOrb
|
  |
| Joined: 02 May 2010 |
| Total Posts: 1206 |
|
|
| 09 May 2013 03:19 PM |
battery = script.Parent function onChanged() battery.Text = battery.Batt.Value end
Battery.Changed:connect(onChanged)
How about this? |
|
|
| Report Abuse |
|
|
IceOrb
|
  |
| Joined: 02 May 2010 |
| Total Posts: 1206 |
|
|
| 09 May 2013 03:34 PM |
| Would that work? to display the intValue in the text label? |
|
|
| Report Abuse |
|
|
IceOrb
|
  |
| Joined: 02 May 2010 |
| Total Posts: 1206 |
|
|
| 09 May 2013 03:47 PM |
| Ah it doesn't seem to work? any help? |
|
|
| Report Abuse |
|
|
IceOrb
|
  |
| Joined: 02 May 2010 |
| Total Posts: 1206 |
|
|
| 09 May 2013 03:49 PM |
This is the error displayed: 21:48:25.671 - Players.Player1.PlayerGui.GUI.Frame.FrameB.Battery.Script:6: attempt to index global 'Battery' (a nil value) 21:48:25.671 - Script "Players.Player1.PlayerGui.GUI.Frame.FrameB.Battery.Script", Line 6 21:48:25.671 - stack end |
|
|
| Report Abuse |
|
|
|
| 09 May 2013 03:49 PM |
IntValues do not have text. It's battery.Value.
You need to link the IntValue to the vehicles. The IntValue is the Battery. Once you sit in the Vehicle, You're Character is linked to the Vehicle, thus allowing you to Link your Player to the vehicle, and your PlayerGui. |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 09 May 2013 03:50 PM |
| In Lua, battery ~= Battery. They are two completely different ideas as Lua is case-sensitive. |
|
|
| Report Abuse |
|
|
IceOrb
|
  |
| Joined: 02 May 2010 |
| Total Posts: 1206 |
|
|
| 10 May 2013 03:16 AM |
| Right I'm very confused, how would I make the IntValue display in the text? |
|
|
| Report Abuse |
|
|
HD188753
|
  |
| Joined: 13 Jun 2012 |
| Total Posts: 5021 |
|
|
| 10 May 2013 06:20 AM |
| Textlabel.Text = "Battery at " .. Intvalue .. "%" |
|
|
| Report Abuse |
|
|
HD188753
|
  |
| Joined: 13 Jun 2012 |
| Total Posts: 5021 |
|
|
| 10 May 2013 06:21 AM |
Oops. Should be intvalue.Value |
|
|
| Report Abuse |
|
|
IceOrb
|
  |
| Joined: 02 May 2010 |
| Total Posts: 1206 |
|
|
| 10 May 2013 11:46 AM |
So it should be this:
battery = script.Parent function onChanged() battery.Text = "Battery at"..intvalue.Value.." end
Battery.Changed:connect(onChanged) |
|
|
| Report Abuse |
|
|
IceOrb
|
  |
| Joined: 02 May 2010 |
| Total Posts: 1206 |
|
| |
|
IceOrb
|
  |
| Joined: 02 May 2010 |
| Total Posts: 1206 |
|
|
| 10 May 2013 12:05 PM |
This is the script: textlabel = script.Parent intvalue = script.Parent.intvalue function onChanged() textlabel.Text = "" ..intvalue.Value.. "%" end
intvalue.Changed:connect(onChanged)
|
|
|
| Report Abuse |
|
|
|
| 10 May 2013 12:29 PM |
function onChanged() textlabel = script.Parent intvalue = script.Parent.intvalue function onChanged() textlabel.Text = (invalue.Value) end
intvalue.Changed:connect(onChanged) |
|
|
| Report Abuse |
|
|
|
| 10 May 2013 12:30 PM |
| Whoops, added an extra function. Ignore the on on top. |
|
|
| Report Abuse |
|
|
IceOrb
|
  |
| Joined: 02 May 2010 |
| Total Posts: 1206 |
|
|
| 10 May 2013 12:32 PM |
| Ignore the one on top? Or the one within the script lines? |
|
|
| Report Abuse |
|
|
IceOrb
|
  |
| Joined: 02 May 2010 |
| Total Posts: 1206 |
|
|
| 10 May 2013 12:35 PM |
| Hm still doesn't seem to be working. |
|
|
| Report Abuse |
|
|
|
| 10 May 2013 12:36 PM |
Where are your Variables? The script is fine.
What is your Output reading? We need more then just, it doesn't work. |
|
|
| Report Abuse |
|
|