Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local snap = 3
- local blocks = game.ReplicatedStorage:WaitForChild("Blocks")
- local placeRE = game.ReplicatedStorage:WaitForChild("PlaceBlockRE")
- local chosenBlock = blocks:GetChildren()[1]
- for i, block in pairs(blocks:GetChildren()) do
- local clonedTemplate = script:WaitForChild("BlockButton"):Clone()
- local name = block.Name
- clonedTemplate.BlockName.Text = name
- local blockClone = block:Clone()
- blockClone.Size = Vector3.new(snap, snap, snap)
- blockClone.Parent = clonedTemplate.BlockImage
- local cam = Instance.new("Camera")
- clonedTemplate.BlockImage.CurrentCamera = cam
- cam.Parent = clonedTemplate.BlockImage
- cam.CFrame = CFrame.new(blockClone.Position + Vector3.new(3.3, 3.3, 3.3), blockClone.Position)
- clonedTemplate.Parent = script.Parent
- clonedTemplate.MouseButton1Click:Connect(function()
- chosenBlock = blocks[name]
- end)
- end
- local mouse = game.Players.LocalPlayer:GetMouse()
- local selectingBox = Instance.new("SelectionBox", workspace)
- game:GetService("RunService").RenderStepped:Connect(function()
- local target = mouse.Target
- if target then
- if target:FindFirstChild("Placeable") then
- selectingBox.Adornee = target
- else
- selectingBox.Adornee = nil
- end
- end
- end)
- local isRemoving = false
- mouse.Button1Down:Connect(function()
- isRemoving = true
- end)
- mouse.Button1Up:Connect(function()
- isRemoving = false
- end)
- local isPlacing = false
- mouse.Button2Down:Connect(function()
- isPlacing = true
- end)
- mouse.Button2Up:Connect(function()
- isPlacing = false
- end)
- game.ReplicatedStorage.PlaySoundRE.OnClientEvent:Connect(function()
- script.Sound:Play()
- end)
- local blockCooldown = 0.08
- while wait() do
- local target = mouse.Target
- if target and target:FindFirstChild("Placeable") then
- if isPlacing then
- placeRE:FireServer(chosenBlock, target, mouse.TargetSurface, "placing")
- wait(blockCooldown)
- elseif isRemoving then
- placeRE:FireServer(nil, target, nil, "removing")
- wait(blockCooldown)
- end
- end
- end
Add Comment
Please, Sign In to add comment