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

How do I get a Motor to keep rotating until you release the Mouse?

Asked by 8 years ago

So I'm building a helicopter like tool that will spin when you click but stop spinning when you release the mouse, right now I created a motor joint that will spin when you click but do it once and never again which is the first problem, the second is that it falls off the joint when I deselect the tool and reselect it, and lastly I tried putting it in a repeat loop until Mouse.Button1Up which is releasing the mouse. What is my problem and how can I fix it? Here's the code.

player = game.Players.LocalPlayer
tool = script.Parent
Rotate1 = tool.Rotate1
Wing1 = game.StarterPack.Wing1
Handle = tool.Handle
Blade1 = tool.Blade1
Blade2 = tool.Blade2

local tool = script.Parent  

local w = Instance.new("Weld") 
    w.Parent = Rotate1
    w.Part0 = Rotate1
    w.Part1 = Blade1
    w.C0 = CFrame.new(0,0,0)
    w.C1 = CFrame.new(-3,0.65,0)

local w2 = Instance.new("Weld")
    w2.Parent = Rotate1
    w2.Part0 = Rotate1
    w2.Part1 = Blade2
    w2.C0 = CFrame.new(0,0,0)
    w2.C1 = CFrame.new(-3,-0.65,0)

local Handle = tool.Handle
local Rotate1 = tool.Rotate1

    local rotate =Instance.new("Motor",game.JointsService)
    rotate.Part0 = tool.Handle
    rotate.Part1 = tool.Rotate1
    rotate.C0 = CFrame.new(3,0,0) * CFrame.Angles(0,math.rad(90),0)
    rotate.C1 = CFrame.new(0,0,0) * CFrame.Angles(0,math.rad(90),0)

    rotate.MaxVelocity = math.rad(0)
    rotate.DesiredAngle = math.rad(0)

function OnClicked(Mouse)

    rotate.MaxVelocity = math.rad(3)
    rotate.DesiredAngle = math.rad(360) 
    wait(0.01)

    repeat

    until Mouse.Button1Up

end

function OnEquipped(Mouse)
    Mouse.Button1Down:connect(OnClicked)
end

tool.Equipped:connect(OnEquipped)

1 answer

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
8 years ago

repeat until Mouse.Button1Up will loop once. Since Mouse.Button1Up exists, the statement is true. If you want to wait until Mouse.Button1Up is triggered, use Mouse.Button1Up:wait()

Ad

Answer this question