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

Why won't the following code work? Mouse.hit

This code is in a Local Script in a tool. It should create parts at the location of the mouse with the Object Hearts as a child of it. It creates the part with the child, but it spawns at 0,0,0. Any ideas?

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

local function onActivate()
	local character = tool.Parent
	local hit = mouse.Hit.p
	local part = Instance.new("Part", character)
	local hearts = tool.Hearts:Clone()
	part.Anchored = true
	part.Size = Vector3.new(1, 1, 1)
	part.CanCollide = false
	part.Position = Vector3.new(hit)
	hearts.Parent = part
end

tool.Activated:connect(onActivate)

2 answers

✓ Accepted answer

mouse.Hit.p is already a Vector3, so you would want to either do CFrame.new(mouse.Hit.p) or do position = mouse.Hit.p

do part.CFrame = CFrame.new(hit) it should work for u since cframe changes the position of an object and i think ur getting position 0,0,0 since i believe thats where parts spawn if u dont change the position

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