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 » Scripting Helpers
Home Search
 

Re: Little help? (CM32 please?)

Previous Thread :: Next Thread 
builderman1171 is not online. builderman1171
Joined: 27 Mar 2010
Total Posts: 1595
14 Apr 2012 07:47 PM
I'd like the game to add points to a #Value when i'm holding down string.byte == 17 (the upArrowKey)

Here's the onKeyDown event
if string.byte(key) == 17 then
local upArrowDown = true
while wait() do
if (upArrowDown == true) and vehicle.Speed.Value < vehicle.MaxSpeed.Value then
vehicle.Speed.Value = vehicle.Speed.Value + 1
end
end
end

and the onKeyDown event

if string.byte(key) == 17 then
upArrowDown = false
end
Report Abuse
builderman1171 is not online. builderman1171
Joined: 27 Mar 2010
Total Posts: 1595
14 Apr 2012 07:50 PM
Bump
Report Abuse
builderman1171 is not online. builderman1171
Joined: 27 Mar 2010
Total Posts: 1595
14 Apr 2012 07:53 PM
Whoop's:

Here's the onKeyDown event

if string.byte(key) == 17 then
local upArrowDown = true
while wait() do
if (upArrowDown == true) and vehicle.Speed.Value < vehicle.MaxSpeed.Value then
vehicle.Speed.Value = vehicle.Speed.Value + 1
end
end
end

and the onKeyUp event

if string.byte(key) == 17 then
upArrowDown = false
end
Report Abuse
XhappysmileX is not online. XhappysmileX
Joined: 22 Feb 2009
Total Posts: 124
14 Apr 2012 07:58 PM
You know, more helpers exist than just Crazyman32 in this enormous forum of sophistication and quarrels.

Your script has no way to even register any event - as there isn't one. You just have blocks of code made up of if statements. Is there no tool/hopperbin (which is required to get the key state.
Report Abuse
builderman1171 is not online. builderman1171
Joined: 27 Mar 2010
Total Posts: 1595
14 Apr 2012 08:01 PM
Oh, forgot, I men to tell you I left out the actual function but here I go.
-------
function onKeyDown(key)

if string.byte(key) == 17 then
local upArrowDown = true
while wait() do
if (upArrowDown == true) and vehicle.Speed.Value < vehicle.MaxSpeed.Value then
vehicle.Speed.Value = vehicle.Speed.Value + 1
end
end
end

end

------------------------------

function onKeyUp(key)

if string.byte(key) == 17 then
    upArrowDown = false
end

end
------


And then I have an onSelected() function to activate these. All inside a HopperBin
Report Abuse
XhappysmileX is not online. XhappysmileX
Joined: 22 Feb 2009
Total Posts: 124
14 Apr 2012 08:06 PM
Please post the whole script, as parts of it just don't suffice for a good working environment for anyone to correct asses and debug your problem.
Report Abuse
builderman1171 is not online. builderman1171
Joined: 27 Mar 2010
Total Posts: 1595
14 Apr 2012 08:06 PM
My whole script? Okay...

bin = script.Parent
plane = nil
hold = false
local debounce = false
local planedebounce = false
local stuntdebounce = false
local controlling = false
local currentspeed = 0
local turn = nil
local CanShoot = true
local owner = game.Players.LocalPlayer
fly = false

function computeDirection(vec)
    local lenSquared = vec.magnitude * vec.magnitude
    local invSqrt = 1 / math.sqrt(lenSquared)
    return Vector3.new(vec.x * invSqrt, vec.y * invSqrt, vec.z * invSqrt)
end

function move(point, engine)
    local origincframe = engine:findFirstChild("Direction").cframe
    size = engine.Size

    target = engine.Position+((point - engine.Position).unit*100)
    local dir = (target - engine.Position).unit
    local spawnPos = engine.Position
    left = engine.CFrame*CFrame.new(-size.x/2, 0, 0).p
    right = engine.CFrame*CFrame.new(size.x/2, 0, 0).p
    md = (target - engine.Position).magnitude

    foebmd = engine.CFrame*CFrame.new(0, 0, -md).p
    toleft = (target -left).magnitude
    toright = (target -right).magnitude
    rot = ((foebmd - target).magnitude/10)
    local pos = spawnPos + (dir * 1)
    turn = math.rad((rot/10)*engine.TiltFactor.Value)
    if turn ​> math.rad(89) then
    turn = math.rad(89)
    end
    if toleft< toright and toleft ​>rot then
        engine:findFirstChild("Direction").cframe = CFrame.new(pos, pos + dir)*CFrame.fromEulerAnglesXYZ(0, 0, turn)
    elseif toleft ​> toright and toright ​>rot then
        engine:findFirstChild("Direction").cframe = CFrame.new(pos, pos + dir)*CFrame.fromEulerAnglesXYZ(0, 0, -turn)
    else
        engine:findFirstChild("Direction").cframe = CFrame.new(pos, pos + dir)
    end
    if engine:findFirstChild("Direction").maxTorque == Vector3.new(4e3,0,4e3) then
        engine:findFirstChild("Direction").maxTorque = Vector3.new(4e3,4e3,4e3)
    end
    engine:findFirstChild("Direction").P = engine.TurnSpeed.Value
end

function findPlane(player)
    local list = player.Character:GetChildren()
    for x = 1, #list do
        if (list[x].Name == "AircraftSeat") then
            return list[x]
        end
    end
    return nil
end

function onButton1Down(mouse)
    local vehicle = findPlane(script.Parent.Parent.Parent)
    if vehicle ~= nil and debounce == false and planedebounce == false then
    if fly == false and taxi == false then return end
    debounce = true

    while true do
        wait()
        local engine = vehicle
        local position = mouse.Hit
        local target = position.p
        move(target, engine)
        if planedebounce == true or
        controlling == false then break end
    end
    wait(0.1)
    debounce = false
    end
end

function onButton1Up(mouse)
    controlling = true
end

function onSelected(mouse)
    mouse.Icon = "http://www.roblox.com/asset/?id=7419350"
    game.Workspace.CurrentCamera.CameraSubject = bin.Parent.Parent.Character.Head
    game.Workspace.CurrentCamera.CameraType = "Attach"
    mouse.Button1Down:connect(function() onButton1Down(mouse) end)
    mouse.Button1Up:connect(function() onButton1Up(mouse) end)
    mouse.KeyDown:connect(onKeyDown)
    mouse.KeyUp:connect(onKeyUp)
    mouse.Move:connect(function() Fly(mouse) end)
    mouse.Idle:connect(function() Fly(mouse) end)
    controlling = true
end

function onDeselected(mouse)
    game.Workspace.CurrentCamera.CameraSubject = bin.Parent.Parent.Character.Humanoid
    game.Workspace.CurrentCamera.CameraType = "Custom"
end

function Fly(mouse)
    local vehicle = findPlane(script.Parent.Parent.Parent)
    if (vehicle==nil) then return end
    vehicle.Thrust.velocity = (vehicle.CFrame.lookVector * currentspeed) + Vector3.new(0,vehicle.LiftTrim.Value/100,0)
end

function onKeyDown(key)
    if (key~=nil) then
        key = key:lower()
        local vehicle = findPlane(script.Parent.Parent.Parent)
        if (vehicle==nil) then return end
            if key == "y" then
                if game.Players.LocalPlayer.PlayerGui:findFirstChild("Controls") then
                    game.Players.LocalPlayer.PlayerGui:findFirstChild("Controls").Main.engineSign.Visible = false
                end
                fly = true
                vehicle.Direction.cframe = vehicle.CFrame
                vehicle.Direction.maxTorque = Vector3.new(4e3,4e3,4e3)
                vehicle.Thrust.maxForce = Vector3.new(9e20,9e20,9e20)
                while fly == true do
                    if currentspeed < vehicle.Speed.Value then
                        currentspeed = currentspeed + 1
                    elseif currentspeed ​> vehicle.Speed.Value then
                        currentspeed = currentspeed - 1
                    end
                    if vehicle.Acceleration.Value ​> 1000 then vehicle.Acceleration.Value = 1000 end
                    if vehicle.EngineSound.Value ​> 0 then
                    vehicle["EngineSound".. vehicle.EngineSound.Value].Pitch = (currentspeed/240) + (vehicle["EngineSound".. vehicle.EngineSound.Value].BasePitch.Value/100)
                    end
                    wait((1-(vehicle.Acceleration.Value/1000))+0.01)
                    if fly == false then break end
                end
            end
            --[[if key == "x" then
                fly = false
                currentspeed = 0
                vehicle.Direction.maxTorque = Vector3.new(0,0,0)
                vehicle.Thrust.maxForce = Vector3.new(0,0,0)
                if vehicle.EngineSound.Value ​> 0 then
                vehicle["EngineSound".. vehicle.EngineSound.Value].Pitch = (currentspeed/240) + (vehicle["EngineSound".. vehicle.EngineSound.Value].BasePitch.Value/100)
                end
            end]]--
            --if key == "f" and CanShoot == true then
            if string.byte(key) == 17 then
            local upArrowDown = true
            while wait() do
            if (upArrowDown == true) and vehicle.Speed.Value < vehicle.MaxSpeed.Value then
            vehicle.Speed.Value = vehicle.Speed.Value + 1
            end
            end
                --if vehicle.Speed.Value < vehicle.MaxSpeed.Value then
                    --vehicle.Speed.Value = vehicle.Speed.Value + 10
                --end
            end
            if string.byte(key) == 18 then
            local downArrowDown = true
            while wait() do
            if (downArrowDown == true) and vehicle.Speed.Value < vehicle.MinSpeed.Value then
            vehicle.Speed.Value = vehicle.Speed.Value - 1
            end
            end
            end
            if string.byte(key) == 32 then
                game.Players.LocalPlayer.Character.Humanoid.Health = 0
                if game.Players.LocalPlayer.Character:findFirstChild("Plane") then
                    game.Players.LocalPlayer.Character:findFirstChild("Plane"):Destroy()
                end
                if game.Players.LocalPlayer.Character:findFirstChild("AircraftSeat") then
                    game.Players.LocalPlayer.Character:findFirstChild("AircraftSeat"):Destroy()
                end
                game.Workspace.CurrentCamera.CameraSubject = bin.Parent.Parent.Character.Humanoid
                game.Workspace.CurrentCamera.CameraType = "Custom"
            end
    end
end

function onKeyUp(key)
    if (key~=nil) then
        key = key:lower()
        local vehicle = findPlane(script.Parent.Parent.Parent)
        if (vehicle==nil) then return end
    end
    if string.byte(key) == 17 then
        upArrowDown = false
    end
    if string.byte(key) == 18 then
        downArrowDown = false
    end
end

bin.Selected:connect(onSelected)
bin.Deselected:connect(onDeselected)
Report Abuse
builderman1171 is not online. builderman1171
Joined: 27 Mar 2010
Total Posts: 1595
14 Apr 2012 08:07 PM
Toward the bottom you'll see the onKeyUp an onKeyDown event's.
Report Abuse
XhappysmileX is not online. XhappysmileX
Joined: 22 Feb 2009
Total Posts: 124
14 Apr 2012 08:12 PM
It's extremely obvious that is not your script and you just chunked some code in the middle of the KeyDown connected function. Now the problem there is you have two while loops in the same function - and while your flying the one you want with the keys to change the speed is never going to happen when you want it.

In essence - you need to revamp the whole thing (the KeyDown part at most)
Report Abuse
builderman1171 is not online. builderman1171
Joined: 27 Mar 2010
Total Posts: 1595
14 Apr 2012 08:14 PM
My friend gave me this code as a gift. I honestly never found a use until now. But, how would I beable to do what i'm trying to do?
Report Abuse
builderman1171 is not online. builderman1171
Joined: 27 Mar 2010
Total Posts: 1595
14 Apr 2012 08:15 PM
Here's the uneddited code:

bin = script.Parent
plane = nil
hold = false
local debounce = false
local planedebounce = false
local stuntdebounce = false
local controlling = false
local currentspeed = 0
local turn = nil
local CanShoot = true
local owner = game.Players.LocalPlayer
fly = false
function computeDirection(vec)
local lenSquared = vec.magnitude * vec.magnitude
local invSqrt = 1 / math.sqrt(lenSquared)
return Vector3.new(vec.x * invSqrt, vec.y * invSqrt, vec.z * invSqrt)
end
function move(point, engine)
local origincframe = engine:findFirstChild("Direction").cframe
size = engine.Size
target = engine.Position+((point - engine.Position).unit*100)
local dir = (target - engine.Position).unit
local spawnPos = engine.Position
left = engine.CFrame*CFrame.new(-size.x/2, 0, 0).p
right = engine.CFrame*CFrame.new(size.x/2, 0, 0).p
md = (target - engine.Position).magnitude

foebmd = engine.CFrame*CFrame.new(0, 0, -md).p
toleft = (target -left).magnitude
toright = (target -right).magnitude
rot = ((foebmd - target).magnitude/10)
local pos = spawnPos + (dir * 1)
turn = math.rad((rot/10)*engine.TiltFactor.Value)
if turn ​> math.rad(89) then
turn = math.rad(89)
end
if toleft< toright and toleft ​>rot then
    engine:findFirstChild("Direction").cframe = CFrame.new(pos, pos + dir)*CFrame.fromEulerAnglesXYZ(0, 0, turn)
elseif toleft ​> toright and toright ​>rot then
    engine:findFirstChild("Direction").cframe = CFrame.new(pos, pos + dir)*CFrame.fromEulerAnglesXYZ(0, 0, -turn)
else
    engine:findFirstChild("Direction").cframe = CFrame.new(pos, pos + dir)
end
if engine:findFirstChild("Direction").maxTorque == Vector3.new(4e3,0,4e3) then
    engine:findFirstChild("Direction").maxTorque = Vector3.new(4e3,4e3,4e3)
end
engine:findFirstChild("Direction").P = engine.TurnSpeed.Value
end
function findPlane(player)
local list = player.Character:GetChildren()
for x = 1, #list do
if (list[x].Name == "AircraftSeat") then
return list[x]
end
end
return nil
end
function onButton1Down(mouse)
local vehicle = findPlane(script.Parent.Parent.Parent)
if vehicle ~= nil and debounce == false and planedebounce == false then
if fly == false and taxi == false then return end
debounce = true
while true do
    wait()
    local engine = vehicle
    local position = mouse.Hit
    local target = position.p
    move(target, engine)
    if planedebounce == true or
    controlling == false then break end
end
wait(0.1)
debounce = false
end
end
function onButton1Up(mouse)
controlling = true
end
function onSelected(mouse)
mouse.Icon = "http://www.roblox.com/asset/?id=7419350"
game.Workspace.CurrentCamera.CameraSubject = bin.Parent.Parent.Character.Head
game.Workspace.CurrentCamera.CameraType = "Attach"
mouse.Button1Down:connect(function() onButton1Down(mouse) end)
mouse.Button1Up:connect(function() onButton1Up(mouse) end)
mouse.KeyDown:connect(onKeyDown)
mouse.KeyUp:connect(onKeyUp)
mouse.Move:connect(function() Fly(mouse) end)
mouse.Idle:connect(function() Fly(mouse) end)
controlling = true
end
function onDeselected(mouse)
game.Workspace.CurrentCamera.CameraSubject = bin.Parent.Parent.Character.Humanoid
game.Workspace.CurrentCamera.CameraType = "Custom"
end
function Fly(mouse)
local vehicle = findPlane(script.Parent.Parent.Parent)
if (vehicle==nil) then return end
vehicle.Thrust.velocity = (vehicle.CFrame.lookVector * currentspeed) + Vector3.new(0,vehicle.LiftTrim.Value/100,0)
end
function onKeyDown(key)
if (key~=nil) then
key = key:lower()
local vehicle = findPlane(script.Parent.Parent.Parent)
if (vehicle==nil) then return end
if key == "y" then
if game.Players.LocalPlayer.PlayerGui:findFirstChild("Controls") then
game.Players.LocalPlayer.PlayerGui:findFirstChild("Controls").Main.engineSign.Visible = false
end
fly = true
vehicle.Direction.cframe = vehicle.CFrame
vehicle.Direction.maxTorque = Vector3.new(4e3,4e3,4e3)
vehicle.Thrust.maxForce = Vector3.new(9e20,9e20,9e20)
while fly == true do
if currentspeed < vehicle.Speed.Value then
currentspeed = currentspeed + 1
elseif currentspeed ​> vehicle.Speed.Value then
currentspeed = currentspeed - 1
end
if vehicle.Acceleration.Value ​> 1000 then vehicle.Acceleration.Value = 1000 end
if vehicle.EngineSound.Value ​> 0 then
vehicle["EngineSound".. vehicle.EngineSound.Value].Pitch = (currentspeed/240) + (vehicle["EngineSound".. vehicle.EngineSound.Value].BasePitch.Value/100)
end
wait((1-(vehicle.Acceleration.Value/1000))+0.01)
if fly == false then break end
end
end
--[[if key == "x" then
fly = false
currentspeed = 0
vehicle.Direction.maxTorque = Vector3.new(0,0,0)
vehicle.Thrust.maxForce = Vector3.new(0,0,0)
if vehicle.EngineSound.Value ​> 0 then
vehicle["EngineSound".. vehicle.EngineSound.Value].Pitch = (currentspeed/240) + (vehicle["EngineSound".. vehicle.EngineSound.Value].BasePitch.Value/100)
end
end]]--
--if key == "f" and CanShoot == true then
if string.byte(key) == 17 then
if vehicle.Speed.Value < vehicle.MaxSpeed.Value then
vehicle.Speed.Value = vehicle.Speed.Value + 10
end
end
if string.byte(key) == 18 then
vehicle.Speed.Value = vehicle.Speed.Value - 10
end
end
end
if string.byte(key) == 32 then
game.Players.LocalPlayer.Character.Humanoid.Health = 0
if game.Players.LocalPlayer.Character:findFirstChild("Plane") then
game.Players.LocalPlayer.Character:findFirstChild("Plane"):Destroy()
end
if game.Players.LocalPlayer.Character:findFirstChild("AircraftSeat") then
game.Players.LocalPlayer.Character:findFirstChild("AircraftSeat"):Destroy()
end
game.Workspace.CurrentCamera.CameraSubject = bin.Parent.Parent.Character.Humanoid
game.Workspace.CurrentCamera.CameraType = "Custom"
end
end
end
function onKeyUp(key)
if (key~=nil) then
key = key:lower()
local vehicle = findPlane(script.Parent.Parent.Parent)
if (vehicle==nil) then return end
end
end
bin.Selected:connect(onSelected)
bin.Deselected:connect(onDeselected)
Report Abuse
builderman1171 is not online. builderman1171
Joined: 27 Mar 2010
Total Posts: 1595
14 Apr 2012 08:17 PM
So, as you can see I didn't change much of the code. just a tad bit. Now, can you please help me with what i'm trying to do? Is there a better way to do it?
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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