I'm trying to make a boat script, where, when a player is seated, they can make the boat rotate left by pressing the "a" button, make it rotate right by pressing the "d" button, etc. However, the part named "body" does not seem to be rotating. Please help, here is the code:
local debounce = false script.Parent.Touched:connect(function(hit) if debounce == true then return end if debounce == false then debounce = true local h = hit.Parent:findFirstChild("Humanoid") if h == nil then debounce = false return end if h ~= nil then if h.Sit == true then control(h) end end end end)
function control(Humanoid) local turningleft = false local turningright = false local mouse = Humanoid.Parent:GetMouse() if turningleft == false or turningright == false then while true do wait(0.5) mouse.KeyDown:connect(function(key) if key == "a" then turningleft = true while true do wait(0.3) if turningleft == true then local body = script.Parent.Parent.Body local bx, by, bz = body.Rotation.x, body.Rotation.y, body.Rotation.z bz = bz + 1 body.Rotation = Vector3.new(bx, by, bz) end if turningleft == false then return end end end end) end end mouse.KeyUp:connect(function(key) if key == "a" then turningleft = false end end) end
Sorry, let me post the code in a code block:
local debounce = false script.Parent.Touched:connect(function(hit) if debounce == true then return end if debounce == false then debounce = true local h = hit.Parent:findFirstChild("Humanoid") if h == nil then debounce = false return end if h ~= nil then if h.Sit == true then control(h) end end end end) function control(Humanoid) local turningleft = false local turningright = false local mouse = Humanoid.Parent:GetMouse() if turningleft == false or turningright == false then while true do wait(0.5) mouse.KeyDown:connect(function(key) if key == "a" then turningleft = true while true do wait(0.3) if turningleft == true then local body = script.Parent.Parent.Body local bx, by, bz = body.Rotation.x, body.Rotation.y, body.Rotation.z bz = bz + 1 body.Rotation = Vector3.new(bx, by, bz) end if turningleft == false then return end end end end) end end mouse.KeyUp:connect(function(key) if key == "a" then turningleft = false end end) end