【问题标题】:Continuous "input:1: attempt to index a nil value (global 'game')" Error连续\“输入:1:尝试索引一个零值(全局\'游戏\')\”错误
【发布时间】:2022-11-05 10:01:42
【问题描述】:

我开始使用 Lua 制作游戏,并且正在尝试制作排行榜系统。但是我尝试使用 3 种编码类似结果的方法,但它没有运行,说 “输入:1:尝试索引零值(全局'游戏')”这些事件都不是我的

game.Players.PlayerAdded:Connect(function(player)
    
    local leaderstats = instance.new("Folder,player")
    leaderstats.Name = "leaderstats"

    local Points = instance.new("IntValue,leaderstats")
    points.Name = "Points"
    
    local XP = instance.new("IntValue,leaderstats")
    xp.Name = "XP"
    
end)
game.Players.PlayerAdded:Connect(function(player)

    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player
    
    local cash = Instance.new ("IntValue")
    cash.Name = "Cash"
    cash.Value = 0
    cash.Parent = leaderstats
    
end)
local players = game:GetService('Players')

players.PlayerAdded:Connect(function(player)
    if player then 
        local folder = Instance.new('Folder')
        folder.Name = "leaderstats"
        folder.Parent = player
        local gold = Instance.new('IntValue')
        gold.Name = "Gold"
        gold.Parent = folder
        gold.value = 125
    end
end)

所有这些事件都应该在 roblox gui 中创建排行榜,因为它发生在我从中获得它们的创建者身上。但是,当我测试运行游戏时,什么也没有发生,当我把它放在 Lua:demo 中时,它显示:“input:1:尝试索引一个 nil 值(全局'游戏')”

任何帮助将非常感激。

【问题讨论】:

    标签: lua roblox


    【解决方案1】:

    'game' 不是 lua 中的全局值,它只存在于 roblox 中。您应该尝试使用 roblox studio 来测试涉及 roblox 使用的环境变量的脚本。

    【讨论】:

      【解决方案2】:

      我以前在 Roblox Studio 中没有发生过这种情况,你在使用它吗?如果没有,我更喜欢你使用它并再试一次。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-11-03
        • 1970-01-01
        • 2018-03-22
        • 1970-01-01
        • 2018-11-11
        • 2015-04-09
        相关资源
        最近更新 更多