Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

1 comment

0

keydown is decaperated

2 answers

✓ Accepted answer

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.