*I am trying to get a players data by having a script detecting if a player has joined, then use a module script to get the data. It just doesn’t wanna work. There isn’t any errors.
*I’ve attempted to remove my data, going into a live server, setting it into an empty table. There isn’t any errors.
*Script:
local module = {}
local players = game:GetService("Players")
local datastore = game:GetService("DataStoreService")
print("meme2")
local infods = datastore:GetDataStore("InfoDatastoreV6")
print("meme3")
local DefaultBanReason = "Cheating"
local DefaultUnbanDate = "Never."
local DefaultInfoTable = {
InAMatch = false,
Wins = 0,
Losses = 0,
Draws = 0,
Banned = true,
BanReason = DefaultBanReason,
BanDate = "0.0.0000",
UnbanDate = "Never."
}
function module.GetPlayerData(player)
if player == nil then return nil end
local id = player.UserId
local function NewUserData(useridx)
local table1 = infods:SetAsync(useridx,DefaultInfoTable)
return DefaultInfoTable
end
local data = infods:GetAsync(id) or NewUserData(id)
if data.Banned then
for i,v in pairs(players:GetChildren()) do
if v.UserId == id then
v:Kick("Banned! Reason: "..data.BanReason..". Ban date: "..data.BanDate..". Unban date: "..data.UnbanDate..".")
end
end
return end
end
return module
I am aware that I should use pcall, and I previously did use pcall.
Oopsie, gave you the wrong version of the script. I was testing the ban system and had it set on true(still on my most recent script), and it should kick the player out of the game which it doesn’t. The tables content is all nil, nothing is what it should be.
It still has the problem I mentioned earlier but it looks like the banning part should work. You don’t need to loop through all the players though as you already have a reference to the player.
e.g
if data.Banned then
player:Kick("Banned! Reason: "..data.BanReason..". Ban date: "..data.BanDate..". Unban date: "..data.UnbanDate..".")
return nil
end
return data
data.Banned is nil, and I’ve reset my data multiple times and changed the datastore name. I have a script to handle stuff if there’s a new player joining to make data for the user. But it isn’t working.
No need to iterate through players to see if anyone is banned, just compare to Player.UserId.
As you’ve pointed out, call in protected mode.
That aside, it would be most wise to add print() calls to see what code is and is not running, and to also show the saving code and code that calls the module. Check to make sure that this code is all running, too.