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

How would i make a snap grid for my placement system?

here is the local script. I've tried making the grid system with math.floor but it didn't work at all so my guess is that it is outdated.

local Mouse = game.Players.LocalPlayer:GetMouse()
local BuildMode = false
local UIS = game:GetService("UserInputService")
local Target = nil
local BuildMode2 = false
local Run = game:GetService("RunService")
local Rotating = false
local RotatingSpeed = 0.2
local de = false
local PosX = math.floor(Mouse.Hit.X/1 + 0.5) * 1
local PosY = Mouse.Hit.Y
local PosZ = math.floor(Mouse.Hit.Z/1 + 0.5) * 1
Mouse.Button1Down:Connect(function()
	if BuildMode == true then
		game.ReplicatedStorage.RemoteEvent:FireServer(Mouse.Hit.Position,Target.CFrame,Target.Name)
	end
end)
Mouse.Move:Connect(function()
	local Build = Target
	if Build then
		Build.Position = Vector3.new(PosX,PosY,PosZ)
	end
end)
Run.RenderStepped:Connect(function()
	local Build = Target
	if Rotating == true and de == false then
		Build.CFrame = Build.CFrame * CFrame.fromEulerAnglesXYZ(0,0.1,0)
		de = true
		wait(RotatingSpeed)
		de = false
	end
end)
UIS.InputBegan:Connect(function(k,p)
	if p then return end
	if k.KeyCode == Enum.KeyCode.E then
		if BuildMode == false then
			BuildMode = true
			BuildMode2 = true
			local ClientBuilding = game.ReplicatedStorage.Build1:Clone()
			ClientBuilding.Parent = workspace
			ClientBuilding.Transparency = 0.5
			ClientBuilding.Color = Color3.fromRGB(0,255,0)
			ClientBuilding.CanCollide = false
			Target = ClientBuilding
			Mouse.TargetFilter = ClientBuilding
			print(Target.Name)
		else
			BuildMode = false
			Target:Destroy()
			Target = nil
			BuildMode2 = false
		end
	elseif k.KeyCode == Enum.KeyCode.R then
		Rotating = true
	end
end)

UIS.InputEnded:Connect(function(k,p)
	if k.KeyCode == Enum.KeyCode.R then
		Rotating = false
	end
end)

2 comments

0

what do you mean grid system?

0

like snap grid when you move your mouse the object moves 1 stud with it so it goes to the nearsest stud to the mouse position

1 answer

So you don't need s script for this. you need to get to {model} like there {Home} {Model} {Test} {View} {Plugins} when you get to {Model} there should be this box call snap to grid, and if u change the stud, you can move in different stud. If this make no sense tell me and I make a little video

2 comments

0

this is not what i mean i made a placement system and im trying to make a snap grid on it.

0

ooh sorry

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