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

Orientation of the part in the model always returns to 0,0,0 when ever the mouse is moved?

Asked by 5 years ago
Edited 5 years ago

Orientation of the part in the model always returns to 0,0,0 when ever the mouse is moved

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

local BuildMode = false

local GridSize = 11

local PosX
local PosY
local PosZ

local Material = game.ReplicatedStorage.BuildPart.BuildMaterial

mouse.KeyDown:Connect(function(key)
    if key == "f" and BuildMode == false then
        BuildMode = true
        local MaterialClone = Material.Parent:Clone()
        MaterialClone.Parent = workspace
        MaterialClone.BuildMaterial.Transparency = 0.5
        MaterialClone.BuildMaterial.CanCollide = false
        local function Snap()
            PosX = math.floor(mouse.Hit.X / GridSize + 0.5) * GridSize
            PosY = math.floor(mouse.Hit.Y / GridSize + 0.5) * GridSize
            PosZ = math.floor(mouse.Hit.Z / GridSize + 0.5) * GridSize
        end
        local function Movement()
            mouse.TargetFilter = MaterialClone
            Snap()
            MaterialClone:SetPrimaryPartCFrame(CFrame.new(PosX,PosY,PosZ))
        end
        mouse.Move:Connect(Movement)
    end
end)
0
keydown is decaperated User#23365 30 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

lines 22, 23,24,25 Hit.p for hit.position you can also type hit.position but hit.p works

function Snap()
            PosX = math.floor(mouse.Hit.X / GridSize + 0.5) * GridSize
                PosY = math.floor(mouse.Hit.p.Y / GridSize + 0.5) * GridSize
                PosZ = math.floor(mouse.Hit.p.Z / GridSize + 0.5) * GridSize
            Rot = (((mouse.Hit - mouse.Hit.p.X) - Mouse.Hit.p.Y) - mouse.Hit.p.Z)
end

line 29

 MaterialClone:SetPrimaryPartCFrame(CFrame.new(PosX,PosY,PosZ) + Rot)

also you should look into userinputservice keydown is deprecated and local functions are not good to use just delete the snap function and replace when you call it with the code in the function

Ad
Log in to vote
0
Answered by 5 years ago

lines 22, 23,24,25 Hit.p for hit.position you can also type hit.position but hit.p works

view source 1 function Snap() 2 PosX = math.floor(mouse.Hit.X / GridSize + 0.5) * GridSize 3 PosY = math.floor(mouse.Hit.p.Y / GridSize + 0.5) * GridSize 4 PosZ = math.floor(mouse.Hit.p.Z / GridSize + 0.5) * GridSize 5 Rot = (((mouse.Hit - mouse.Hit.p.X) - Mouse.Hit.p.Y) - mouse.Hit.p.Z) 6 end line 29

view source 1 MaterialClone:SetPrimaryPartCFrame(CFrame.new(PosX,PosY,PosZ) + Rot) also you should look into userinputservice keydown is deprecated and local functions are not good to use just delete the snap function and replace when you call it with the code in the function

Answer this question