Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

cframe rotation and restart function ...help?

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

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.