如何在 Roblox Lua 中的当前鼠标位置生成部件?

How to spawn a part at the current mouse position in Roblox Lua?

我一直在为 Roblox 编写脚本。这是代码:

local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Activation = 
Instance.new("Sound",game.Players.LocalPlayer.Character.Head)
local char = Player.Character
local hum = char.Humanoid
local root = char.HumanoidRootPart

UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.F then
    Activation.SoundId = "rbxassetid://1581091676" --Plays Mangekyou Sharingan Activation Sound.
    Activation:Play()
    wait(0.3)       
    game.Players.LocalPlayer.Character.Head.face.Texture = "rbxassetid://76285632" --When F is pressed, face texture changes to sharingan decal.
    game:GetService("Chat"):Chat(Player.Character.Head, "Mangekyou Sharingan!")
end
end)

UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R then
    Activation.SoundId = "rbxassetid://1580990602" --Plays Amaterasu Activation Sound.
    Activation:Play()
    game:GetService("Chat"):Chat(Player.Character.Head, "Amaterasu!")
    local Target = Instance.new("Part") --makes a part
    Target.Parent = game.Workspace
    Target.Position = Vector3.new(Mouse.target.Position) --makes the part spawn where the mouse is 
    Target.Transparency = 1 
    Target.Anchored = true 
    Target.CanCollide = false 

    local Amaterasu = Instance.new("Fire")
    Amaterasu.Parent = game.Workspace.Part
    Amaterasu.Color = Color3.new(0,0,0)
    Amaterasu.SecondaryColor = Color3.new(0,0,0) --amaterasu properties
    Amaterasu.Size = 25

    local R = Instance.new("RocketPropulsion") --rocket propulsion, parents amaterasu
    R.Parent = Amaterasu
    R.MaxThrust = 300
    R.ThrustP = 30
    R:Fire()
end
end)

UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.G then
    game.Players.LocalPlayer.Character.Head.face.Texture = "rbxassetid://22557247" --When G is pressed, face texture changes back to normal.(leaves face blank isnt working :/)
end
end)
-----------------------------

我需要帮助的是在游戏中我鼠标的当前位置生成天照大神开火的部分。我研究并尝试了 Target.Position = Vector3.new(Mouse.target.Position)Target.Position = Vector3.new(Mouse.Hit).

这些都不起作用,最终结果是无论我的鼠标在游戏中的位置如何,零件都会在底板中间生成。

这是票

local Part = Instance.new("Part",game.Workspace);
Part.CFrame = Mouse.Hit;

我们需要的是CFrame。所以我们会做:

Target.CFrame = CFrame.new(Mouse.target.Position)