Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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

Log in to vote
1
Answered by
RayCurse 1518 Moderation Voter
6 years ago
Edited 6 years ago

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
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? wilsonsilva007 373 — 6y
Ad

Answer this question