Hello, I am making a building game.I already have the pickup block script but I can't build with it. Can anyone help me and add the script to place the block down to anywhere I click my mouse? thank you
Here is the code I have
local tool = script.Parent.Parent local click = script.Parent.ClickDetector
local function pickup(player) tool.Parent = game.Workspace [player.name ]
end
click.MouseClick: Connect (pickup)
I think it's this:
local function round(vector,grid) return Vector3.new( math.floor(vector.X/grid+.5)*grid, math.floor(vector.Y/grid+.5)*grid, math.floor(vector.Z/grid+.5)*grid ) end round(mouse.Hit.Position,3)
or:
-- services local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local Workspace = game:GetService("Workspace") local player = Players.LocalPlayer local block = ReplicatedStorage:WaitForChild("block") -- how far you want the player to reach local REACH = 100 mouse.Button2Down:Connect(function() local unitRay = mouse.UnitRay local castParams = RaycastParams.new() castParams.FilterDescendantsInstances = { player.Character } -- automatically ignores the player's character local result = Workspace:Raycast( unitRay.Origin, unitRay.Direction * REACH, castParams ) if result then local newBlock = block:Clone() newBlock.Position = round(result.Position + result.Normal * 1.5, 3) newBlock.Parent = workspace end end)
I'm not really good at scripting.