For some reason I get
00:10:40.513 - ServerScriptService.Stats:21: attempt to index a number value
Pretty strange I dont see what Im doing wrong, Im trying to make it know if the player has played the game before if he did then set his data, or else just make a new one then set it
local DataStoreService = game:GetService("DataStoreService"):GetDataStore("PertendCodeIsHere")
game.Players.PlayerRemoving:Connect(function(LeavingPlayer)
DataStoreService:SetAsync(LeavingPlayer.userId, LeavingPlayer.stats.Wallet.Value)
DataStoreService:SetAsync(LeavingPlayer.userId, LeavingPlayer.stats.Bank.Value)
end)
function onPlayerEntered(newPlayer)
--Money--
local stats = Instance.new("IntValue")
stats.Name = "stats"
stats.Parent = newPlayer
local money = Instance.new("IntValue")
money.Name = "Money"
money.Parent = stats
if DataStoreService:GetAsync(newPlayer.userId) ~= nil then
money.Value = DataStoreService:GetAsync(newPlayer.userId, newPlayer.stats.Money.Value)[1]
else
local NewDataBank = money.Value + 50
DataStoreService:SetAsync(newPlayer.userId, money.Value)
money.Value = DataStoreService:GetAsync(newPlayer.userId, money.Value)
end
local bank = Instance.new("IntValue")
bank.Name = "Bank"
bank.Parent = stats
if DataStoreService:GetAsync(newPlayer.userId, newPlayer.stats.Bank.Value) ~= nil then
bank.Value = DataStoreService:GetAsync(newPlayer.userId, newPlayer.stats.Bank.Value)[1]
else
local NewDataBank = bank.Value + 200
DataStoreService:SetAsync(newPlayer.userId, bank.Value)
bank.Value = DataStoreService:GetAsync(newPlayer.userId, bank.Value)
end
--Pin Number--
local PinNumber = Instance.new("StringValue")
PinNumber.Name = "PinNumber"
PinNumber.Value = math.random(10000,99999)
PinNumber.Parent = newPlayer
--Hunger--
local Hunger = Instance.new("IntValue")
Hunger.Name = "Food"
local money = Instance.new("IntValue")
money.Name = "Hunger"
money.Value = 10
local bank = Instance.new("IntValue")
bank.Name = "Thirst"
bank.Value = 10
money.Parent = Hunger
bank.Parent = Hunger
Hunger.Parent = newPlayer
--Player Can run--
local CanRun = Instance.new("BoolValue")
CanRun.Name = "CanRun"
CanRun.Parent = newPlayer
newPlayer.CanRun.Value = true
--Jail--
local IsInJail = Instance.new("BoolValue")
IsInJail.Name = "IsInJail"
IsInJail.Parent = newPlayer
local TimeLeftInJail = Instance.new("NumberValue")
TimeLeftInJail.Name = "TimeLeftInJail"
TimeLeftInJail.Parent = IsInJail
--JobValues and all that--
local Amountoftrashthismanpickedups = Instance.new("NumberValue")
Amountoftrashthismanpickedups.Name = "Amountoftrashthismanpickedups"
Amountoftrashthismanpickedups.Parent = newPlayer
local ShirtCharacterIsWearing = Instance.new("StringValue")
ShirtCharacterIsWearing.Name = "ShirtID"
ShirtCharacterIsWearing.Parent = newPlayer
newPlayer.Character.Shirt.ShirtTemplate = "rbxassetid://10248083"
end
game.Players.ChildAdded:Connect(onPlayerEntered)
