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

Help with CFrame?

Asked by 9 years ago

How would I move this model by 10 studs and follow the mouse?

I tried making the part move 10 studs by multiplying the CFrame of the model by 10,but it didn't work.

it just moved 10 studs from the mouse away from the part.

I want it to move like the Select Tool in studio.

How would I do this?

-- 6/10/2015  By:Zobomafoo
--Purpose:Creates a movable model using rays and mouse events

--[[Setup]]--

Player = game.Players.LocalPlayer
-------------------------------
Vairables = {
    Part = game.ServerStorage.Part,
    Mouse = Player:GetMouse()}
-------------------------------
ClonedPart = Vairables.Part:Clone()
ClonedPart.Parent = game.Workspace
-------------------------------
IgnoreTable = {Player.Character,ClonedPart}
-------------------------------
Functions = {
    CreateRay = function()
    local Ray = Ray.new(Vairables.Mouse.UnitRay.Origin,Vairables.Mouse.UnitRay.Direction*900)--Create ray from mouse and reaches 900 studs max
    local Hit,Pos = game.workspace:FindPartOnRayWithIgnoreList(Ray,IgnoreTable)
    return Hit,Pos
end}
 --~~--~~[[Everything starts here]]~~--~~---
     Vairables.Mouse.Move:connect(function()
         local Hit,Pos = Functions.CreateRay()
         if  Hit then -- if hit then do the following
         ClonedPart:SetPrimaryPartCFrame(CFrame.new(Pos + Vector3.new(0,ClonedPart.PrimaryPart.Size.y / 2,0)*10))
--adding half the part's Y Size because then the part will be above the ground rather in halfway into the ground

         end
     end)
 -----------------------------------------
     Vairables.Mouse.Button1Down:connect(function()
         local NewPart = ClonedPart:Clone()
         NewPart.Parent = game.Workspace
     end)


1 answer

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

I assume you want to move it 10 studs straight up?

Try changing line 27 to this:

ClonedPart:SetPrimaryPartCFrame(CFrame.new(Pos + Vector3.new(0,ClonedPart.PrimaryPart.Size.y / 2,0) + Vector3.new(0, 10, 0)))
0
I want to move it on the X and Y but I want the mouse to still be on top of the Model.You get me? kevinnight45 550 — 9y
0
For example you're able to change the increment of studs in the using the "Select" tool and the mouse will still stay on top of it.It won't go out of reach. kevinnight45 550 — 9y
0
I'm afraid I don't understand what you mean. Send me a ROBLOX PM with a place using this Tool where we can talk in person. adark 5487 — 9y
Ad

Answer this question