Database problem

Hello,

why I do not get the same things about “dataPlayer” ? It’s the same process but I do not get the same data…

Normal: {"ap":100,"ban":true,"banReason":"TK","endBan":0,"name":"ptitloup132","rank":"Premier"} 

No normal: {"816024195":{"ap":100,"ban":true,"banReason":"TK","endBan":0,"name":"ptitloup132","rank":"Premier"},"FORMAT":{"ap":0,"ban":false,"banReason":"N/A","endBan":0,"name":"username","rank":"Rookie"}}  

Module script:

local FirebaseService = require(game:GetService("ServerScriptService"):WaitForChild('FirebaseService'))
local database = FirebaseService:GetFirebase("players");

local BanMan = {}

BanMan.update = function(playerID, value, reason)
	local dataPlayer = database:GetAsync(playerID)
	local sendData = game:GetService("HttpService"):JSONDecode(dataPlayer)
	sendData["ban"] = value
	sendData["banReason"] = reason
	database:SetAsync(playerID, game.HttpService:JSONEncode(sendData))	
end 

BanMan.banned = function(playerID)
	local dataPlayer = database:GetAsync(playerID)
	print(dataPlayer) -- Normal
	local sendData = game:GetService("HttpService"):JSONDecode(dataPlayer)
	return sendData.ban
end

BanMan.getReason = function(playerID)
	local dataPlayer = database:GetAsync(playerID)
	print(dataPlayer) --Problem here
	local sendData = game:GetService("HttpService"):JSONDecode(dataPlayer)
	return sendData.banReason
end

return BanMan

Data (from firebase):
image

If you do not know where do I found scripts to communicate with Firebase: Firebase Database Tutorial

Hello, sorry for the inconvenience, it came from a script that used the module and everything is back to normal!

You should use functions instead of defining the player everytime, check if reason = nil

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.