如何在 roblox 中让模型在我旁边生成?

问题描述 投票:0回答:2

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

我尝试使用此功能,但它只是给我一个错误,提示“尝试使用‘字符’索引编号”

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)
lua roblox
2个回答
0
投票

.MouseButton1Down
事件返回 X 和 Y 屏幕坐标(以像素为单位),而不是玩家 如 api 参考中指定的那样

因此执行

5.Character
会导致错误

现在解决你的问题

假设这是一个本地脚本

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)

0
投票

@eenNaampje 我用汽车尝试过这个并工作,但我不能坐在里面

© www.soinside.com 2019 - 2024. All rights reserved.