Roblox - Argument 1 缺失或为空

我正在编写一个脚本,当你触摸角色的碰撞箱时,会出现某些聊天信息,但输出窗口会显示"Argument 1 missing or nil"。

代码:

local debounce = false

game.Workspace.RowanAsleep.RowanAsleepHitbox.Touched:Connect(function(hit)

    if not debounce then
        debounce = true
        if game.Players:GetPlayerFromCharacter(hit.Parent)then
            game.ReplicatedStorage.RowanTalking.RowanSleeping:FireClient()
        end
        wait(2)
        debounce = false
    end
end)
点赞
用户13661384
用户13661384

在第8行,FireClient()需要传递一个玩家实例。尝试使用GetPlayerFromCharacter的结果创建一个变量,然后将其传递给FireClient。

local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then --GetPlayerFromCharacter只会返回nil或玩家实例
    game.ReplicatedStorage.RowanTalking.RowanSleeping:FireClient(player)
end
2020-06-01 21:36:09