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

cframe rotation and restart function ...help?

Asked by 6 years ago

i've worked out how to move a part (boat) to mouse.hit position...but would also like it to rotate face slowly toward hit point. plus if the mouse is hit a second time, how would i stop the function mid flow and restart the function, at its new position?

boat = game.Workspace.Part
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local time = 5
local increment = 0.1
local debounce = false




mouse.Button1Down:connect (function()
    local mousecframe = mouse.Hit
    local mouseposition = mousecframe.p
    print ("mouse position on hit = ",mouseposition)

    local newpos = Vector3.new(mouseposition.X,mouseposition.Y,mouseposition.Z)
    print("newpos = ",newpos)
    local diff = newpos - boat.Position 
    print("diff = ",diff)
    local mag = diff.magnitude 
    print("mag = ",mag)
    local Direction = CFrame.new(boat.Position, newpos).lookVector
    print("direction is = ", Direction)

        for n = 0, mag, increment do 
        print (n )
        boat.CFrame = boat.CFrame + (Direction * increment) -- * CFrame.Angles(newpos)
        wait( (time/mag) * increment ) 


        end
end)

1 answer

Log in to vote
1
Answered by
cailir 284 Moderation Voter
6 years ago

You can't print a non string item. Your script should be:

Move = game.Workspace.MoveMe
local player = game.Players.LocalPlayer
local time = 5
local increment = 0.1
local debounce = false
local mouse = player:GetMouse()

mouse.Button1Down:connect(function()
    local mousecframe = mouse.Hit
    local mouseposition = mousecframe.p

    local newpos = Vector3.new(mouseposition.X,mouseposition.Y,mouseposition.Z)
    local diff = newpos - Move.Position 
    local mag = diff.magnitude 
    local Direction = CFrame.new(Move.Position, newpos).lookVector

        for n = 0, mag, increment do 
        print (n )
        Move.CFrame = Move.CFrame + (Direction * increment) -- * CFrame.Angles(newpos)
        wait( (time/mag) * increment ) 


        end
end)
Ad

Answer this question