Below is the script that's erroring.
local Players = game:GetService("Players") local kickCommand = "!kick " local function onOwnerChatted(player, message) if message:sub(1, kickCommand:len()):lower() == kickCommand:lower() then local name = message:sub(kickCommand:len() + 1) local playerToKick = Players:FindFirstChild(name) if playerToKick then playerToKick:Kick("Our moderators have determined that your behavior at SF Nuclear Lab has been in violation of our rules. Therefore, you are kicked from this game.") else end end end local function onPlayerAdded(player) if player.leaderstats.GVC2YDJ5.Value >= 1 then player.Chatted:Connect(function (...) onOwnerChatted(player, ...) end) end end for _, player in pairs(Players:GetPlayers()) do onPlayerAdded(player) end Players.PlayerAdded:Connect(onPlayerAdded)
Below is the leaderstats script.
local Players = game:GetService("Players") local DataStoreService = game:GetService("DataStoreService") local TestDataStore = DataStoreService:GetDataStore("emp43") local data = { ["22XQ3SGH"] = 0, ["XTSAT8B7"] = 0, ["RVESMDXG"] = 0, ["8YHCNKMD"] = 0, ["D4VWKQF7"] = 0, ["ENB78YBQ"] = 0, ["GVC2YDJ5"] = 0, ["TKBRVCBQ"] = 0, ["6TU53T5F"] = 0, ["A79QBG5C"] = 0 } Players.PlayerAdded:Connect(function(Player) local DataFromStore = nil local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = Player for name, value in pairs(data) do local new = Instance.new("NumberValue") new.Name = name new.Value = value new.Parent = leaderstats end local s, e = pcall(function() DataFromStore = TestDataStore:GetAsync("uid-" .. Player.UserId) end) if s then print("Getting Data For: " .. Player.Name) if DataFromStore then for name, value in pairs(DataFromStore) do Player.leaderstats[name].Value = value end print("Data Loaded For: " .. Player.Name) else print("Created New Data For: " .. Player.Name) end else warn("Error Getting Data For: " .. Player.Name) end -- Check if banned. --if Player:WaitForChild("leaderstats").ENB78YBQ.Value >= 1 then --Player:Kick("Our moderators have determined that your behavior at SF Nuclear Lab has been in violation of our rules. Therefore, you are banned from this game.") --end end) Players.PlayerRemoving:Connect(function(Player) local DataForStore = {} for name, value in pairs(Player.leaderstats:GetChildren()) do DataForStore[value.Name] = value.Value end local success = pcall(TestDataStore.SetAsync, TestDataStore, "uid-" .. Player.UserId, DataForStore) if success then print("Successfully Saved Data For: " .. Player.Name) end end) game:BindToClose(function() for _, v in pairs(game.Players:GetPlayers()) do local success, errormessage = pcall(function() TestDataStore:SetAsync(v.UserId, data) -- define the data, since it's in a different scope end) end end)
First off it should be a serversided script within server script service. You should remove the waitforchild considering they are not very good in serversided scripts. Try this.
local Players = game:GetService("Players") local DataStoreService = game:GetService("DataStoreService") local TestDataStore = DataStoreService:GetDataStore("emp43") local data = { ["22XQ3SGH"] = 0, ["XTSAT8B7"] = 0, ["RVESMDXG"] = 0, ["8YHCNKMD"] = 0, ["D4VWKQF7"] = 0, ["ENB78YBQ"] = 0, ["GVC2YDJ5"] = 0, ["TKBRVCBQ"] = 0, ["6TU53T5F"] = 0, ["A79QBG5C"] = 0 } Players.PlayerAdded:Connect(function(Player) local DataFromStore = nil local leaderstats = Instance.new("Folder", Player) --Parent it within the instance here not there. leaderstats.Name = "leaderstats" for name, value in pairs(data) do local new = Instance.new("NumberValue", leaderstats) --Same thing here. new.Name = name new.Value = value end local s, e = pcall(function() DataFromStore = TestDataStore:GetAsync("uid-" .. Player.UserId) end) if s then print("Getting Data For: " .. Player.Name) if DataFromStore then for name, value in pairs(DataFromStore) do Player.leaderstats[name].Value = value end print("Data Loaded For: " .. Player.Name) else print("Created New Data For: " .. Player.Name) end else warn("Error Getting Data For: " .. Player.Name) end -- Check if banned. if Player.leaderstats.ENB78YBQ.Value >= 1 then --Assuming your having the problem here. I will fix it up. Player:Kick("Our moderators have determined that your behavior at SF Nuclear Lab has been in violation of our rules. Therefore, you are banned from this game.") end end) Players.PlayerRemoving:Connect(function(Player) local DataForStore = {} for name, value in pairs(Player.leaderstats:GetChildren()) do DataForStore[value.Name] = value.Value end local success = pcall(TestDataStore.SetAsync, TestDataStore, "uid-" .. Player.UserId, DataForStore) if success then print("Successfully Saved Data For: " .. Player.Name) end end) game:BindToClose(function() for _, v in pairs(game.Players:GetPlayers()) do local success, errormessage = pcall(function() TestDataStore:SetAsync(v.UserId, data) -- define the data, since it's in a different scope end) end end)