Mouse.Hit is a CFrame
. The explosion Instance takes in a Vector3
property. There's no error in my script. The whole script does execute. Here's the script,
local plr = game:GetService("Players").LocalPlayer local mouse = plr:GetMouse() mouse.Button1Down:connect(function() local Boom = Instance.new("Explosion", game.Workspace) Boom.Position = Vector3.new(mouse.Hit) end)
When I click somewhere, the explosion does not appear. Also, when I checked workspace, the explosion was in workspace, but the position property was 0,0,0.
What's the problem?
Thank you.
According to the wiki, you cannot construct a Vector3 from a CFrame. The only possible constructors are Vector3.new(number x, number y, number z)
, Vector3.FromNormalId(Enum.NormalID normal)
and Vector3.FromAxis(Enum.Axis axis)
.
You could however retrieve the p
property of your mouse.Hit
CFrame, which is a Vector3.
-- As simple as that. explosion.Position = mouse.Hit.p
Hope that helps.
So basically like you said, calling mouse.hit
will return a CFrame so that means we have to make it a Vector3. There are probably better ways to do this but a simple way call the X,Y and Z coordinates from the CFrame which makes it a Vector3 as seen below.
local plr = game:GetService("Players").LocalPlayer local mouse = plr:GetMouse() mouse.Button1Down:connect(function() local Boom = Instance.new("Explosion", game.Workspace) Boom.Position = Vector3.new(mouse.Hit.x, mouse.Hit.y, mouse.Hit.z) -- Converting CFrame into Vector3 end)
Hope this helped, Have fun scripting!