Help with boat movement

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want my boat to have the same movement mechanics on all uses.

  2. What is the issue? The issue is that on every use after the first use the boat seems to maintain its rotational velocity despite the code not changing.

  1. What solutions have you tried so far? I have an align orientation constraint that I thought could be causing the bug, but when I tried disabling it the bug still persists.

I am getting the user input using output = getInputs:InvokeClient(playerOnWheel) and each entry in the table is true or false based on whether w,s,a,d are pressed or not.

I’m sorry its so long but here is my main code when the wheel prompt is triggered this is the script that runs. Any ideas for why it doesn’t act the same on each trigger are appreciated I can’t seem to think of any reasons.

prompt.Triggered:Connect(function(player)
	playerOnWheel = player
	prompt.Enabled = false
	local char = player.Character
	local humanoid = char:FindFirstChild("Humanoid")
	local hrp = char:FindFirstChild("HumanoidRootPart")
	local animator = humanoid.Animator
	aTrack = animator:LoadAnimation(animation)
	
	--load the animation
	repeat task.wait() until aTrack.Length > 0

	aTrack:Play()
	aTrack:AdjustSpeed(0)
	
	--set humanoid location and lock them in the correct orientation
	humanoid.WalkSpeed += 0.01 --these are from a bug where if you change the walk and jump on the client it doesn't update to the server so you need to reupdate it
	humanoid.JumpPower += 0.01
	task.wait(.1)
	humanoid.WalkSpeed = 0 --default 16
	humanoid.JumpPower = 0 --default 50
	char.HumanoidRootPart.Position = Vector3.new(standingLocation.Position.X,char.HumanoidRootPart.Position.Y,standingLocation.Position.Z)
	char.HumanoidRootPart.Orientation = standingLocation.Orientation
	pToShip.Part0 = hrp
	
	--enable leave wheel button
	player.PlayerGui:WaitForChild("LeaveWheel").Enabled = false --same issue as before
	player.PlayerGui:WaitForChild("LeaveWheel").Enabled = true
	
	--disable align orientation it messes with driving (fix later possibly)
	alignOrientation.Enabled = false
	
	while playerOnWheel ~= nil do 
		--raycast
		local sPos = script.Parent.Parent.floatPart.Position
		local ePos = sPos + Vector3.new(0,-5,0) --change based on boat height?
		local ray = workspace:Raycast(sPos,ePos - sPos, Params)
		if ray and ray.Material ~= Enum.Material.Water  then
			forward.Enabled = false
			rightRotation.Enabled = false
			leftRotation.Enabled = false
			backward.Enabled = false
			break
		end
		
		--get player input
		local output = {} --safe invoke mousePosition (from commitblue)
		local timeoutcount = 0
		local timeout = 3
		local cr = task.spawn(function()
			output = getInputs:InvokeClient(playerOnWheel)
		end)
		repeat task.wait(.05) timeoutcount += 1 until timeoutcount >= timeout or output ~= nil

		if output[1] then
			forward.Enabled = true
			
			--check rotations if going backwards
			if output[4] then
				rightRotation.Enabled = true
			else
				rightRotation.Enabled = false
			end
			if output[3] then
				leftRotation.Enabled = true
			else
				leftRotation.Enabled = false
			end
			continue
		else
			forward.Enabled = false
		end
		
		--backwards
		if output[2] then
			backward.Enabled = true
			
			--check rotations if going backwards
			if output[4] then
				rightRotation.Enabled = true
			else
				rightRotation.Enabled = false
			end
			if output[3] then
				leftRotation.Enabled = true
			else
				leftRotation.Enabled = false
			end
			continue
		else
			backward.Enabled = false
		end
		
		--make sure rotation is disabled if they aren't pressed
		if not output[1] and not output[2] then
			rightRotation.Enabled = false
			leftRotation.Enabled = false
		end
	end
	alignOrientation.Enabled = true
	forward.Enabled = false
	rightRotation.Enabled = false
	leftRotation.Enabled = false
	backward.Enabled = false
end)
1 Like