Atomic Studios
Atomic Studios

Reputation: 3

Continuous "input:1: attempt to index a nil value (global 'game')" Error

I'm starting to make games using Lua and i'm trying to make a leaderboard system. However i've tried using 3 methods of coding similar results and it doesn't run, saying "input:1: attempt to index a nil value (global 'game')" none of these events are mine

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)

All of these events are supposed to create leaderboards in the roblox gui as it happened to the creators i got them from. However, when I test run the game, nothing happens and when i put it in Lua:demo, it reads:"input:1: attempt to index a nil value (global 'game')"

Any help would be much appreciated.

Upvotes: 0

Views: 657

Answers (1)

Cinema movies
Cinema movies

Reputation: 46

'game' is not a global value in lua, it is only present in roblox. You should try using roblox studio to test scripts involving enviroment variables that roblox uses.

Upvotes: 2

Related Questions