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

Why this grid placement system code only works on specific baseplate size?

So I made this grid placement system thingy and the block keep floating, so i decided to change the baseplate size and then it somehow works

The code:

local Player = game.Players.LocalPlayer
local plrChar = Player.Character
local mouse = Player:GetMouse()

function SetUp()
	local NewBlock =  script.Part:Clone()
	NewBlock.Parent = workspace
	NewBlock.Transparency = 0.5
	NewBlock.CanCollide = false
	return NewBlock
end

local Thing = SetUp()

function Round(Input, GridSize) 
	local X = math.floor(Input.X / GridSize + 0.5) * GridSize 
	local Y = math.floor(Input.Y / GridSize + 0.5) * GridSize 
	local Z = math.floor(Input.Z / GridSize + 0.5) * GridSize 

	return Vector3.new(X, Y, Z)

end

mouse.Button1Down:Connect(function()
	Thing.CanCollide = true
	Thing.Transparency = 0
	Thing = SetUp()
end)

game:GetService("RunService").RenderStepped:Connect(function()
	Move()
end)


function Move()
	local target = mouse.Hit.p
	local face = mouse.TargetSurface
	mouse.TargetFilter = Thing
	local norm = Vector3.FromNormalId(face)
	Thing.Position = Round(target + (norm * 2), 4)
end

1 answer

Hmm, I'm not completely sure but I'd guess it's something to do with all of the rounding. How big does your baseplate have to be for it to work? And at what size does it stop working?

2 comments

0

idk but it works at 4, 12, 20, 28

0

Maybe a dumb question but why are there 4 numbers? - if you make the "4" smaller does it stop working? If yes then it's probably to do with rounding, just try to have your baseplate big enough or rethink your script :)

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