|
| 17 Apr 2015 06:02 PM |
Everytime I would test the script ( it is in startergui as a local script ) it works perfectly. But if I go in the game, it says it can't find the Character. I tried making it into a varible, it now says it can't find the varible... here's the script
local power = 10 local p = false local player = game.Players.LocalPlayer local character = game.Players.LocalPlayer.Character local mouse = player:GetMouse() local bv = Instance.new("BodyVelocity") bv.Parent = character.Torso bv.maxForce = Vector3.new(0,0,0) bv.velocity = Vector3.new(0,60,0)
mouse.KeyDown:connect(function(key) if key:byte() == 32 and power > 2 then --spacebar is 32 p = true bv.maxForce = Vector3.new(0,400000,0) end end)
mouse.KeyUp:connect(function(key) if key:byte() == 32 then --spacebar is 32 p = false bv.maxForce = Vector3.new(0,0,0) end end)
while wait(.1) do print(power) if power < 11 and p == false then wait(.5) power = power + 1 end if p == true and power > 1 then power = power - 1 --script.Parent.EBar.Size = script.Parent.EBar.Size - UDim2.new(0,0,0,2) humanoid = game.Players.LocalPlayer.Character.Humanoid elseif power < 1 then player.Character.Torso.BodyVelocity.maxForce = Vector3.new(0,0,0) end end
anyone know the bug? :/ |
|
|
| Report Abuse |
|
|
| |
|
|
| 17 Apr 2015 06:19 PM |
I'm guessing wait until the character loads then do it? repeat wait() until game.Players.LocalPlayer.Character:findFirstChild('Torso')
~ All you need to know is that I'm an otaku |
|
|
| Report Abuse |
|
|
mycheeze
|
  |
| Joined: 27 Jun 2011 |
| Total Posts: 6748 |
|
|
| 17 Apr 2015 06:40 PM |
This is a better method
local character = player.Character or player.CharacterAdded:wait()
>This means if it finds a character, it will assign it as 'character', however if it doesn't, it will wait for the character to be added. |
|
|
| Report Abuse |
|
|
mycheeze
|
  |
| Joined: 27 Jun 2011 |
| Total Posts: 6748 |
|
|
| 17 Apr 2015 06:42 PM |
While I'm at it, I will revise your variables
local power, p = 10, false local player = game.Players.LocalPlayer local character = player.Character or player.CharacterAdded:wait() local mouse = player:GetMouse() local bv = Instance.new('BodyVelocity', character:WaitForChild('Torso')) bv.maxForce, bv.Velocity = Vector3.new(0,0,0), Vector3.new(0,60,0) |
|
|
| Report Abuse |
|
|
amanda
|
  |
| Joined: 21 Nov 2006 |
| Total Posts: 5925 |
|
|
| 17 Apr 2015 07:07 PM |
'local character = player.Character or player.CharacterAdded:wait()'
Good, good, good. |
|
|
| Report Abuse |
|
|