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

Block not placing at correct coordinates. Block not being cloned?

Hello! I am trying to create a thing where when they right click it will clone the block and place it in a certain position. But it doesnt work

Code: (Local script in StarterCharacterScripts)

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.Button2Down:Connect(function()
	local block = game.ReplicatedStorage:WaitForChild("Block")
	block:Clone()
	block.Position = Vector3.new(mouse.X, mouse.Y, mouse.Z)
	block.Parent = game.Workspace
end)

Anyone know the fix for this?

1 answer

✓ Accepted answer

You need to get the CFrame of the mouse first with mouse.Hit

block.Position = Vector3.new(mouse.Hit.X, mouse.Hit.Y, mouse.Hit.Z)

Edit:

local block = game.ReplicatedStorage:WaitForChild("Block"):Clone() -- clone it here so block has the value of the clone and not the one in replicated storage
    block.Position = Vector3.new(mouse.X, mouse.Y, mouse.Z)
    block.Parent = game.Workspace

2 comments

0

ok but the block isnt cloning

0

Thats because you are referring to the block in replicated storage and not the cloned block

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