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

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

Asked by 5 years ago

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

Log in to vote
1
Answered by 5 years ago

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

Ad
Log in to vote
1
Answered by 5 years ago

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

Answer this question