Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago
Edited 3 years ago

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

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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
0
ok but the block isnt cloning googlpeopel15 55 — 3y
0
Thats because you are referring to the block in replicated storage and not the cloned block JustinWe12 723 — 3y
Ad

Answer this question