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

Moving a Model to a Mouse Position?

Asked by 9 years ago

Im trying to make a script that teleports a model to the mouses CFrame position! Please Help :D

Output: 18:06:23.346 - CoordinateFrame is not a valid member

target = game.Players.LocalPlayer:GetMouse().Hit
game.Workspace.Model:MoveTo(target)

2 answers

Log in to vote
0
Answered by 9 years ago

The method MoveTo takes a Vector3, not a CoordinateFrame.

Mouse.Hit returns a CoordinateFrame.

http://wiki.roblox.com/index.php?title=API:Class/Mouse/Hit http://wiki.roblox.com/index.php?title=API:Class/Model/MoveTo

target = game.Players.LocalPlayer:GetMouse().Hit
game.Workspace.Model:MoveTo(Vector3.new(target))

Using the Vector3 constructor on the CFrame is a simple and quick way to convert.

Ad
Log in to vote
0
Answered by 5 years ago

To move models with CFrame, you should use :SetPrimaryPartCFrame(**arg1**CFrame) instead of :MoveTo(**arg1** Vector3).

To use :SetPrimaryPartCFrame(), you should first set PrimaryPart by Model's Properties Tab. After setting that, you will be able to use it.

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local model = workspace:WaitForChild("ModelName")

model:SetPrimaryPartCFrame(mouse.Hit)

Answer this question