I am working on my skills with datastores, but, for some reason, It gives me an error that a variable I set is nil.
local Player = game.Players.LocalPlayer local DS = game:GetService("DataStoreService"):GetDataStore("Money") function DataStore(player) local key = "user_" .. player.userId if DS:GetAsync(key) == nil then DS:SetAsync(key,0) print("key Created") else wait(1) player.leaderstats.Money.Value = DS:GetAsync(key) end end function Playeradded(player) local L = Instance.new("IntValue") local M = Instance.new("IntValue") L.Name = "leaderstats" L.Parent = player M.Parent = L M.Name = "Money" end function chatted(message) if message == "money" then Player.leaderstats.Money.Value = Player.leaderstats.Money.Value + 1 end end game.Players.PlayerAdded:connect(Playeradded) game.Players.PlayerAdded:connect(DataStore) Player.Chatted:connect(chatted)
The error it gave me was: 12:41:03.560 - Workspace.Script:28: attempt to index local 'Player' (a nil value)
Looks like your problem is that you are trying to access LocalPlayer within a server-sided Script. LocalPlayer can only be accessed through a LocalScript; if you try to through a Script, it will be equivalent to nil.