我如何才能在roblox中让一个模型在我旁边繁殖



我正试图为我的枪支测试游戏制作一个虚拟产卵器,但我无法让它在玩家旁边产卵

我试着用这个,但它只是给了我一个错误,说";尝试用"字符"对数字进行索引;

script.Parent.MouseButton1Down:Connect(function(player)
local char = player.Character or player.CharacterAdded:Wait()
local pos = char:GetPrimaryPartCFrame().p
local clone = script.Parent.Dummy:Clone()
clone.Parent = game.Workspace
clone:MoveTo(pos)
end)

.MouseButton1Down事件返回以像素为单位的X和Y屏幕坐标,而不是播放器如api参考中所述

因此进行CCD_ 2会导致错误

现在针对您的问题

假设这是一个本地脚本

local player = game.Players.LocalPlayer
script.Parent.MouseButton1Down:Connect(function()
local char = player.Character or player.CharacterAdded:Wait()
local pos = char:GetPrimaryPartCFrame().p
local clone = script.Parent.Dummy:Clone()
clone.Parent = game.Workspace
clone:MoveTo(pos)
end)

最新更新