Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I get these scripts to edit the y axis of a BodyPosition in a seat?

Asked by 7 years ago
Edited 7 years ago

I am trying to make a ship that is driven by BodyGyro, BodyPosition and BodyVelocity all kept inside of a VehicleSeat. Everything works except it does not travel up or down, I made two separate scripts to fix the problem, but neither of them seem to work. The first script just turns the other on and off when a player gets in or out of the seat and the second script changes the y axis of the BodyPosition when the player in the seat presses q or e. Here are the scripts:

Script 1:

local Move = script:FindFirstChild("move")
script.Parent.ChildAdded:connect(function(child)
    if child:IsA"Weld" and child.Name == "SeatWeld" then
        local p1 = child.Part1
        if p1.Parent:IsA"Model" then
            local char = p1.Parent
            if game.Players:FindFirstChild(char.Name) then
                script.Parent.CurrentSeatedPlayer.Value = game.Players[char.Name]
                Move.Disabled = false
            end
        end
    end
end)
script.Parent.ChildRemoved:connect(function(child)
    if child:IsA"Weld" and child.Name == "SeatWeld" then
        Move.Disabled = true
        script.Parent.CurrentSeatedPlayer.Value = nil
    end
end)

Script 2:

pos = script.Parent.Parent:FindFirstChild("BodyPosition")
                function onKeyDown(key)
                    key:lower()
                    if key == "q" then
                        pos.CFrame + Vector3.new(0,(Height/5),0)
                    end
                function onKeyDown(key)
                    key:lower()
                    if key == "q" then
                        pos.CFrame - Vector3.new(0,(Height/5),0)
                    end

1 answer

Log in to vote
0
Answered by 7 years ago

You can't combine CFrame and Vector3.

Fixed Script (2):

pos = script.Parent.Parent:FindFirstChild("BodyPosition")
                function onKeyDown(key)
                    key:lower()
                    if key == "q" then
                        pos.CFrame + CFrame .new(0,(Height/5),0)
                    end
                function onKeyDown(key)
                    key:lower()
                    if key == "q" then
                        pos.CFrame - CFrame .new(0,(Height/5),0)
                    end

(untested)

0
Also, you need to fix the functions (end) nforeman 15 — 7y
Ad

Answer this question