How do I set a models position? Since a models property doesn't have a position point. How do I set a models position to my mouses hit position. Whenever I press play and activate my tool it clones the model and puts the position of the model in the origin of the studio. And the output gives me a error saying "16:32:37.090 - Position is not a valid member of Model"
01 | local tool = script.Parent.Parent |
02 | local ReplicatedStorage = game.ReplicatedStorage |
03 | local RepThermite = ReplicatedStorage.RepThermite |
04 | local plr = game.Players.LocalPlayer |
05 | local Mouse = plr:GetMouse() |
06 |
07 |
08 | tool.Activated:Connect( function () |
09 | local Clonedthermite = RepThermite:Clone() |
10 | Clonedthermite.Parent = game.Workspace |
11 | Clonedthermite.Position = Mouse.hit.p |
12 |
13 |
14 | end ) |
Use Clonedthermite:SetPrimaryPartCFrame(Mouse.Hit)
Note: if your model does not have a primary part, then give it one.
You can use this for mouse location:
1 | local mouseLocation = game:GetService( "UserInputService" ):GetMouseLocation() |
Then cast a ray from the camera:
1 | local unitRay = camera:ScreenpointToRay(mouseLocation.X, mouseLocation.Y) |
2 | local newRay = Ray.new(unitRay.Origin, unitRay.Direction * 100 ) -- 100 is the distance |
Then you cast this ray on workspace:
1 | local part, position, normal = workspace:FindPartOnRay(newRay, character) -- ignore the character in the ray |
2 | -- we don't use part or normal as they're not needed |
3 | Clonedthermite.Position = position |
This is the basic way of setting it at a max of 100 studs where the mouse is
Here is a more advanced tutorial that teaches you how to do it specifically without UserInputService but the Mouse object is generally superseded by UserInputService so it's up to you: https://devforum.roblox.com/t/dragging-objects-with-the-mouse/403766