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

how to round to the nearest 5 in a block placement script?

okay i have this script which has a block and that block position needs to get rounded to the nearest 5 (the same size as the block) ive tried searching up but cant find anything about it please help This is the part of the script that needs editing

BuildBlock.Position = Vector3.new(math.floor(Mouse.Hit.p.X + 0.5),math.floor(Mouse.Hit.p.Y + 0.5),math.floor(Mouse.Hit.p.Z + 0.5))--this rounds to nearest 1 i need it to round to nearest 5

2 comments

0

then change that

0

^the answer to every problem that ever existed

1 answer

✓ Accepted answer

Sorry, I misunderstood at first. Gotchu fam.

Ok, so basically we could divide by 5, remove the decimal and then multiply the result by 5, giving us a result that will always be a factor of 5.

Effectively something like this:

BuildBlock.Position = Vector3.new(math.floor(math.floor(Mouse.Hit.p.X + 0.5)/5)*5,math.floor(math.floor(Mouse.Hit.p.Y + 0.5)/5)*5,math.floor(math.floor(Mouse.Hit.p.Z + 0.5)/5)*5)

This was just off the top of my head, so if it doesn't work, I apologize in advance.

1 comment

0

it worked thanks

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