Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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)

1 comment

0

Also, you need to fix the functions (end)

This discussion is preserved as it was. New answers, comments, and votes are closed.