#Script error

9 messages · Page 1 of 1 (latest)

night wagon
#

It keeps saying Im attempting to put userID with nil. Im not sure how to fix this. Here is the script:
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local RunService = game:GetService("RunService")

local dataStore = DataStoreService:GetDataStore("Test")

local function givePlayerCurrency(player: player)
while true do
task.wait(1)
player.leaderstats.Strength.Value += 1
player.leaderstats.Cash.Value += 1
end
end

local function setupPlayerData(player: player)
local userID = player.UserId
local key = "Player_"..userID

local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"

local strength = Instance.new("IntValue", leaderstats)
strength.Name = "Strength"
strength.Value = 0

local cash = Instance.new("IntValue", leaderstats)
cash.Name = "Cash"
cash.Value = 0

local success, returnValue
success, returnValue = pcall(dataStore.GetAsync, dataStore, key)

if success then 
    if returnValue == nil then
        returnValue = {
            Strength = 0,
            Cash = 0,
        }
    end
    
    print(returnValue)
    strength.Value = if returnValue.Strength ~= nil then returnValue.Strength else 0
    cash.Value = if returnValue.Cash ~= nil then returnValue.Cash else 0
    
else
    player:Kick("Error in your loadout. Please rejoin.")
    print(player.Name.."Data Loading Error")
end
givePlayerCurrency(player)

end

Players.PlayerAdded:Connect(setupPlayerData)

buoyant surge
#

@night wagon can you format it to lua?

gritty mirage
#

It's because you are not giving the player object to the function setUpPlayerData

You are essentially trying to get the userId from nothing

night wagon
#

How should I fix this?

gritty mirage
#

Just connect the function to the connection
Players.PlayerAdded:Connect(function(player) --put the code in the function here end)

night wagon
vocal zodiac
#

"Attempt to put userID with nil" is not a real error

#

It's best you send a copy of the original message