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

How do I set a models position to my mouse?

Asked by 3 years ago

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"

local tool = script.Parent.Parent
local ReplicatedStorage = game.ReplicatedStorage
local RepThermite = ReplicatedStorage.RepThermite
local plr = game.Players.LocalPlayer
local Mouse = plr:GetMouse()


tool.Activated:Connect(function()
    local Clonedthermite = RepThermite:Clone()
    Clonedthermite.Parent = game.Workspace
    Clonedthermite.Position = Mouse.hit.p


end)

0
SetPrimaryPartCFrame greatneil80 2647 — 3y

2 answers

Log in to vote
0
Answered by
Roger111 347 Moderation Voter
3 years ago

Use Clonedthermite:SetPrimaryPartCFrame(Mouse.Hit)

Note: if your model does not have a primary part, then give it one.

Ad
Log in to vote
0
Answered by 3 years ago

You can use this for mouse location:

local mouseLocation = game:GetService("UserInputService"):GetMouseLocation()

Then cast a ray from the camera:

local unitRay = camera:ScreenpointToRay(mouseLocation.X, mouseLocation.Y)
local newRay = Ray.new(unitRay.Origin, unitRay.Direction * 100) -- 100 is the distance

Then you cast this ray on workspace:

local part, position, normal = workspace:FindPartOnRay(newRay, character) -- ignore the character in the ray
-- we don't use part or normal as they're not needed
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

Answer this question