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?

01local tool = script.Parent
02local player = game.Players.LocalPlayer
03local mouse = player:GetMouse()
04 
05local function onActivate()
06    local character = tool.Parent
07    local hit = mouse.Hit.p
08    local part = Instance.new("Part", character)
09    local hearts = tool.Hearts:Clone()
10    part.Anchored = true
11    part.Size = Vector3.new(1, 1, 1)
12    part.CanCollide = false
13    part.Position = Vector3.new(hit)
14    hearts.Parent = part
15end
16 
17tool.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