【问题标题】:Roblox Studio- attempt to index nil with 'leaderstats' error in outputRoblox Studio-尝试在输出中使用“leaderstats”错误索引 nil
【发布时间】:2022-01-10 07:21:00
【问题描述】:

所以我想做这个,所以当我点击它时,它会给我一个“硬币”,但它不起作用并说尝试用“leaderstats”索引 nil

`game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new('Folder', player)
leaderstats.Name = 'leaderstats'

local coins = Instance.new('IntValue', leaderstats)
coins.Name = 'Coins'
coins.Value = 0
end)


game.ReplicatedStorage.Remotes.Add.OnServerEvent:Connect(function()
local currency = 'Coins'
local amount = 5
player.leaderstats[currency].Value = player.leaderstats[currency].Value + amount
end)``

【问题讨论】:

    标签: game-development roblox


    【解决方案1】:

    你忘记了OnServerEvent 中的“player”参数,这就是为什么它是 nil

    修复:

    game.ReplicatedStorage.Remotes.Add.OnServerEvent:Connect(function(player) --added player parameter
    local currency = 'Coins'
    local amount = 5
    player.leaderstats[currency].Value = player.leaderstats[currency].Value + amount
    end)
    

    【讨论】:

      猜你喜欢
      • 2020-11-22
      • 2020-12-16
      • 1970-01-01
      • 2022-10-13
      • 2022-01-05
      • 2020-08-17
      • 2021-09-30
      • 2020-08-16
      • 2022-10-24
      相关资源
      最近更新 更多