So I have a script which saves player data into a table here is the script:
game.Players.PlayerRemoving:Connect(function(plr) if plr.CanSave.Value then local specialKey = "User_"..plr.UserId local plrName = plr.Name local plrInfo = game.ServerStorage:FindFirstChild(plrName):WaitForChild("PlayerInfo") if plrInfo.OwnsTycoon.Value then local tycoonName = plrInfo.OwnedTycoon.Value local tycoon = game.Workspace.Tycoons:FindFirstChild(tycoonName) local moneyToSave = plrInfo.Money.Value local buildLevelToSave = plrInfo.BuildLevel.Value local purchasedItemsTable = getTableForDataStore(tycoon, plrInfo) local mainTableToSave = {moneyToSave, buildLevelToSave, purchasedItemsTable} local success, message = pcall(function() mainDataStore:SetAsync(specialKey, mainTableToSave) end) end end end
When a player touches the tycoon door this fires however it is kicking the player(me) every time here is that script:
local mainDataStore = game:GetService("DataStoreService"):GetDataStore("exampledatastore") script.Parent.Touched:Connect(function(hit) if script.Parent.CanCollide then if hit.Parent:FindFirstChild("Humanoid") then -- more irrelevant code here local mainDataTable local plr = game.Players:GetPlayerFromCharacter(hit.Parent) local specialKey = "User_"..plr.UserId local success, message = pcall(function() mainDataTable = mainDataStore:GetAync(specialKey) end) if success then -- some code here else print("Player Data Failed To Load Successfully") -- this stuff is what is happening plr:FindFirstChild("CanSave").Value = false plr:Kick("Your Data Failed To Load Successfully Please Rejoin") end end end end)
Could someone help me figure out what is wrong? Thanks! Note: The game saves ok. It is the loading that is the problem