Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to get/create Datastore tables? [ANSWERED]

Currently, I am trying to make a script for a global banned list. I am trying to add playerIds to a table and possibly retrieve these playerIds. So far I got the part down where I can match playerIds (raw data for them though) and the part where they get kicked. Other than that I need help. Can anyone lead me in the right direction (new to using DataStores and I don't understand the wiki well)?

1 comment

0

You've already got the saving portion down and you're now trying to get the saved values...? Or do you need help with both saving and fetching?

1 answer

✓ Accepted answer

referencing or creating new data store name

local DataStore = game:GetService('DataStoreService'):GetDataStore('Name');
local Players = game:GetService('Players')

function to authenticate player ban status if true, banned, elseif false, not? :D

function RequestBanStatus(player)
    return DataStore:GetAsync(player.userId)
end

function to update playerId's data store depending on boolean argument

local SetBanState = function(playerId, boolean)
	DataStore:UpdateAsync(playerId ,function(state)
		if boolean == false then
			return false
		else
			return true
		end
	end)
end

calls RequestBanStatus function and kicks player if returned value true

Players.PlayerAdded:connect(function(player)
	if RequestBanStatus(player) then
		pcall(function()
			print(player,'banned')
		end)
	end
end)

You could also create a BindableEvent and connect it to the SetBanState function so that you can call it in your chat based administration scripts. You can also create a table within the script containing permanently banned userIds which you would of course add in the RequestBanStatus function in addition to the already existing check.

local DataStore = game:GetService('DataStoreService'):GetDataStore('Name');
local Players = game:GetService('Players')


local SetBanState = function(playerId, boolean)
	DataStore:UpdateAsync(playerId ,function(state)
		return boolean or state
	end)
end
function RequestBanStatus(player)
    return DataStore:GetAsync(player.userId) 
end

Players.PlayerAdded:connect(function(player)

	if RequestBanStatus(player) then
		pcall(function()
			warn('player, banned')
		end)
	end
end)

4 comments

0

If you don't mind me asking. How would I possibly be able to get a playerid from a table (ie. IXLKIDDO returns this id, Imagelabel returns that id, Randomperson returns another id) when it's their name

0

Do you mean getting any player's userId or fetching it from an already existing table?

0

Fetching it from an already existing table. What I've done is try and make a DataStore:SetASync but when I try and fetch people's playerId (when their name is inside of the table), it won't work.

0

save their userIds as key instead of usernames, and then get their names when you fetch the userId

This discussion is preserved as it was. New answers, comments, and votes are closed.