Hey! I haven't asked a question in a while, but here is my issue. So say I want to run a loop when a key is pressed. This works, but I have a problem; I need to break the loop to be able to call another loop. I think I'm able to pull this off but I haven't figured out how. Here's the script I have:
--Wait for player--
repeat wait() until game.Players.LocalPlayer
repeat wait() until game.Players.LocalPlayer.Character
--Variables--
plr = game.Players.LocalPlayer
trial = game.Workspace.Trial
bike = trial.Bike
rider = trial.Rider
leans = bike.Leans
back = leans.Back
front = leans.Front
vert = leans.Vert
--Hold--
plr.Character.Humanoid.WalkSpeed = 0
plr.Character.Torso.Anchored = true
--Functions--
function LeanBack()
while true do wait()
rider.Pos.BodyPosition.Position = back.Position
end
end
function LeanFront()
while true do wait()
rider.Pos.BodyPosition.Position = front.Position
end
end
--Key downs--
--The important part--
local Mouse = plr:GetMouse()
Mouse.KeyDown:connect(function(key)
if key == "a" then
--here I was thinking an if statement such as [if LeanFront.IsPlaying then LeanFront break end] or something. I really can't figure out how.
LeanBack()
end
if key == "d" then
--same here
LeanFront()
end
end)
Thanks! If you could link me to any sources on something like this, that would be great!

1 comment
[INSERT BLUETASLEM COMMENT HERE]