Block Placement System Like Roblox bedwars

local Blocks = {}
local Folder
local FolderPlace
local Storage = script.Parent.Storage
local Block = Storage.ServerData.Blocks.PrototypeWool
local BlockProperties = Storage.ServerData.BlockProperties
local Prediction = Storage.ServerData.Blocks.BlockPrediction
local Outline = Storage.ServerData.Selection.BlockPlacement
local RandomName = math.random(1,5000)
local NewSelection = Outline:Clone()
NewSelection.Parent = workspace
NewSelection.Name = "Outline_"..RandomName.."_"

function Blocks:HoverBlocks(fold)

	Folder = fold
	for i, v in pairs(Folder:GetDescendants()) do
	--	while true do
			if v:IsA("Part") and v.Name == "Prediction2" then

				local RBXEvent = v:FindFirstChild("RBXHover")
				RBXEvent.MouseHoverEnter:Connect(function()
					NewSelection.Adornee = v.Parent.BlockPlacement
				end)
				RBXEvent.MouseHoverLeave:Connect(function()
					NewSelection.Adornee = nil
				end)

				--[@ELSEIF, For the top and bottom part]    
			elseif v:IsA("Part") and v.Name == "Prediction" then

				local RBXEvent2 = v:FindFirstChild("RBXHover")
				local PartToShow = v.Parent.Core

				RBXEvent2.MouseHoverEnter:Connect(function()
					NewSelection.Adornee = PartToShow
				end)
				RBXEvent2.MouseHoverLeave:Connect(function()
					NewSelection.Adornee = nil
			    end)
			
			    --[@ELSEIF, For the top and bottom part]    
	   	    elseif v:IsA("UnionOperation") and v.Name == "PredictionSide" then

			   local RBXEvent3 = v:FindFirstChild("RBXHover")
  
			   RBXEvent3.MouseHoverEnter:Connect(function()
			       NewSelection.Adornee = v
			   end)
			   RBXEvent3.MouseHoverLeave:Connect(function()
				   NewSelection.Adornee = nil
			   end)

		    end
		--	wait(1)
	--	end
	end

end

function Blocks:Place(Fold)
	
	FolderPlace = Fold
	
	for i, v in pairs(FolderPlace:GetDescendants()) do
	--while true do
		if v:IsA("Part") and v.Name == "Prediction2" then
			local NewBlock = Block:Clone()
			local NewProperties = BlockProperties:Clone()
			local NewBlockPrediction = Prediction:Clone()

			local RBXEvent = v:FindFirstChild("RBXHover")
			RBXEvent.MouseClick:Connect(function()
				NewBlock.Parent = FolderPlace
				NewBlock.CFrame = v.Parent.BlockPlacement.CFrame
				NewProperties.Parent = NewBlock
				NewBlockPrediction.Parent = NewBlock
				NewBlock.Orientation = Vector3.new(0,0,0)
				NewBlockPrediction.Core.Orientation = NewBlock.Orientation
				NewBlockPrediction:SetPrimaryPartCFrame(NewBlock.CFrame)
				v:Destroy()
			end)
			
			--[@ELSEIF, For the top and bottom part]    	
		elseif v:IsA("Part") and v.Name == "Prediction" then
			local NewBlock = Block:Clone()
			local NewProperties = BlockProperties:Clone()
			local NewBlockPrediction = Prediction:Clone()

			local RBXEvent = v:FindFirstChild("RBXHover")
			RBXEvent.MouseClick:Connect(function()
				NewBlock.Parent = FolderPlace
				NewBlock.CFrame = v.BlockPlacement.CFrame
				NewProperties.Parent = NewBlock
				NewBlockPrediction.Parent = NewBlock
				NewBlock.Orientation = Vector3.new(0,0,0)
				NewBlockPrediction.Core.Orientation = NewBlock.Orientation
				NewBlockPrediction:SetPrimaryPartCFrame(NewBlock.CFrame)
				v:Destroy()
			end)
			
		elseif v:IsA("UnionOperation") and v.Name == "PredictionSide"	then
			local NewBlock = Block:Clone()
			local NewProperties = BlockProperties:Clone()
			local NewBlockPrediction = Prediction:Clone()

			local RBXEvent = v:FindFirstChild("RBXHover")
			RBXEvent.MouseClick:Connect(function()
				NewBlock.Parent = FolderPlace
				NewBlock.CFrame = v.CFrame
				NewProperties.Parent = NewBlock
				NewBlockPrediction.Parent = NewBlock
				NewBlock.Orientation = Vector3.new(0,0,0)
				NewBlockPrediction.Core.Orientation = NewBlock.Orientation
				NewBlockPrediction:SetPrimaryPartCFrame(NewBlock.CFrame)
				v:Destroy()
			end)
			
		end
	--	wait(1)
--	end
	end
	
end

return Blocks

SERVER SCRIPT

local rs = game:GetService("ReplicatedStorage")
local block = require(rs.SkywarsX.BlockHitboxPrediction)

while true do
	wait(0.03)
	block:Place(workspace.ServerBlockStorage)
end

LOCAL SCRIPT

local rs = game:GetService("ReplicatedStorage")
local block = require(rs.SkywarsX.BlockHitboxPrediction)

while true do
	wait(0.03)
	block:HoverBlocks(workspace.ServerBlockStorage)
end
1 Like

in the server script,

every .03 seconds a block is placed?

wait let me check brb
because for the local script if I dont do that it just stop making the outline appear

yeah so if I remove that everytime I place a block I cant place the next time then

it doesnt place the block on the newly block placed prediction

ok so maybe when ever a user clicks their mouse button(in local script) you can fire a remote event and on server detect it and place block with a debounce

so instead of it placing every .03 seconds it places with a cooldown when ever someone clicks block

and use raycast to detect where they are placing

can you kinda edit the script? Since I dont know exactly what you meant

I already got the raycast values if you want

			RayTop = Ray.new(v.Parent.Position, Vector3.new(0, 15, 0))
			RayBottom = Ray.new(v.Parent.Position, Vector3.new(0, -15, 0))
			RaySideOne = Ray.new(v.Parent.Position, Vector3.new(-15, 0, 15))
			RaySideTwo = Ray.new(v.Parent.Position, Vector3.new(15, 0, 15))
			RaySideThree = Ray.new(v.Parent.Position, Vector3.new(-15, 0, -15))
			RaySideFour = Ray.new(v.Parent.Position, Vector3.new(15, 0, -15))
			RayFront = Ray.new(v.Parent.Position, Vector3.new(0, 0, 15))
			RayBack = Ray.new(v.Parent.Position, Vector3.new(0, 0, -15))
			RayLeft = Ray.new(v.Parent.Position, Vector3.new(15, 0, 0))
			RayRight = Ray.new(v.Parent.Position, Vector3.new(-15, 0, 0))

im not gonna script your game for you im gonna give you directions to learn and become a better dev

basically bad habbits like using while loops without waits or some sort of catch is bad
only run Place() when a remote event is fired when someone clicks

so you have your local script, call the players mouse and when ever theres a mouse click run a remote event (parse the raycast values too) and create a debounce, in the remote even place the block without a while loop

1 Like

ooooh remote event kk i’ll try that

ye cause your placing a block every .03 seconds which will kill any server, so try and avoid while loops in most situations

I’ll try and get back to you when its done

we cant fire remotes from a module right?

does the local script do anything? like the while loop in local script

You can fire remotes from a module, modules are basically just scripts.

ohk because one time i tried it didnt fire