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

How to save a table in a server and not a player?

I have the following table:

BannedPeople = {"PlaceRebuster","BuilderProAwensome","SomeoneElse"--[[More players ahead]]}

From what i've known about DataStores is that it only saves values for players and not server.

Everytime there's new players entering the table, but when I leave, the new values vanish.

Any idea on how I can save this table on the server?

I would really appreciate!

1 answer

Datastores are not limited to just players. In fact, you can make the key of a datastore any string you want. However in this case, I would make a data store wherein the keys are player ids (don't use player names!) and the values are bools indicating whether or not the player is banned.


local DataStoreService = game:GetService("DataStoreService")
local BannedPlayersStore = DataStoreService:GetDataStore("GameData")

function banPlayer (id)
	local success , errorMsg = pcall(function()
		BannedPlayersStore:SetAsync(tostring(id) , true)
	end)
	if not success then
		warn("Failed on SetAsync(.."id.." , true) to BannedPlayersStore")
		warn(errorMsg)
	end
end

function removeBanFromPlayer (id)
	local success , errorMsg = pcall(function()
		BannedPlayersStore:SetAsync(tostring(id) , false)
	end)
	if not success then
		warn("Failed on SetAsync(.."id.." , false) to BannedPlayersStore")
		warn(errorMsg)
	end
end

function isBanned (id)
	local success , banned = pcall(function()
		return BannedPlayersStore:GetAsync(tostring(id))
	end)
	if not success then
		warn("Failed on GetAsync(.."id..") to BannedPlayersStore")
		warn(banned)
		return nil
	end
	return banned
end

game.Players.PlayerAdded:Connect(function(player)
	if isBanned(player.UserId) then
		player:Kick("You cannot join because you have been banned.")
	end
end

1 comment

0

I would have to recode all of my 100+ lines script, isn't there any other way to save each value with a loop to a DataStore?

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