Firebase database

Hello developers, I have a script below that creates a table in firebase if there isnt already one for the player in the database. However the table comes out as
image
When it should just have that player ID and the miles, not any of the -NMOk8NN_z0KTZtNX0qD

How would I fix this?


	local Data = HttpService:JSONDecode(HttpService:GetAsync(URL)) 

	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = Player

	local Miles = Instance.new("StringValue")
	Miles.Name = "Points"

	Miles.Parent = leaderstats
	
	
	
	local Table = {
		[Player.UserId] =  {
			["Miles"] = 0
		}
	}
	
	
	if Data[tostring(Player.UserId)] then

		Miles.Value = Data[tostring(Player.UserId)].Miles
		
	else
		print(Player.Name .. " is not in the database.")
		Miles.Value = 0
		local data = HttpService:RequestAsync(
			{
				Url = URL,  
				Method = "POST",
				Headers = {
					["Content-Type"] = "application/json"  
				},
				Body = HttpService:JSONEncode(Table)
			}
		)

		print(data)
	end

Have you tried printing out HttpService:JSONEncode(Table)?

PS: I guess DataStoreService isn’t something that is usable for this?

I think it’s just a key for your database in firebase, I haven’t worked with firebase before but that key should be a constant string, if so, u can just do data = <the request>[<key>].

That prints this {"1679345517":{"Miles":0}}

and to, msix29’s point, the combination changes whenever you put in new data, I couldn’t find anything on the firebase api, but here it is. Firebase API Reference
image

1 Like

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