Basically, I made a script from a grid placement system tutorial, since I don’t know how to make this correctly. It works fine when the step is 1, however if I change it, the part doesn’t spawn at the mouse’s location, but rather somewhere 1000 studs away. What could be the issue?
Script:
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local tweenservice = game:GetService("TweenService")
local info = TweenInfo.new(0.25, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local Block = script:WaitForChild("Block")
Block.Anchored = true
Block.Orientation = Vector3.new(0,0,0)
local BlockGhost = Block:Clone()
BlockGhost.Parent = workspace
BlockGhost.Transparency = 0.5
BlockGhost.CanCollide = false
Mouse.TargetFilter = BlockGhost
local step = 4
Mouse.Move:Connect(function()
local MousePos = Mouse.Hit.Position
local BlockPos = Vector3.new(0, Block.Size.Y / 2, 0)
BlockPos += MousePos
local XPos = math.round(BlockPos.X / step)
local YPos = math.round(BlockPos.Y)
local ZPos = math.round(BlockPos.Z / step)
BlockPos = Vector3.new(XPos, YPos, ZPos)
local tween = tweenservice:Create(BlockGhost, info, {Position = BlockPos}):Play()
end)
Mouse.Button1Down:Connect(function()
local NewBlock = Block:Clone()
NewBlock.Parent = workspace.Blocks
NewBlock.Position = BlockGhost.Position
end)