Help with saving data

Hello, I would like to know if someone can help me to save a bool value in the player and that this is saved in the server please :frowning:

I need to create a boolValue that is Parent to the player and that this value is saved in the servers, I need to be able to manipulate this bool value in the future, sorry for the inconvenience :frowning:

example:

boolValue false → when the player joins the server boolValue true → the value true will be saved in the player if it leaves and enters the server it will always be true

I have read about saving the data and it has been very complicated for me… I really can’t understand how to do this :frowning:

I need it to happen after this, I want to make that whoever has the value true cannot enter the server again and whoever has the value false can enter

if Player.TeamColor == BrickColor.new("Slime green") then
			for i,Player2 in pairs(Players:GetPlayers()) do
				if message == '.ban ' .. Player2.Name then
					print("The player name is ..." .. Player2.Name)
					print("You have been banned by the administrator")
					-- How could i ban the player here?
					-- code to ban the player here:
				end
			end
		end

I need a bit more info, when do you want it to be saved to the server? When they press a button, or reach a certain level?

1 Like

I need it to happen after this, I want to make that whoever has the value true cannot enter the server again and whoever has the value false can enter

if Player.TeamColor == BrickColor.new("Slime green") then
			for i,Player2 in pairs(Players:GetPlayers()) do
				if message == '.ban ' .. Player2.Name then
					print("The player name is ..." .. Player2.Name)
					print("You have been banned by the administrator")
					-- How could i ban the player here?
					-- code to ban the player here:
				end
			end
		end

Entire game, or that specific server? And why are you using a bool? That isn’t needed in this case.

@PipeSader I already provided a possible solution to that in your other one relating to this, for the ban stuff

I will send you the model for it in PM’s later

1 Like

On the current server that is being played

If you want to ban someone only from the current server, you don’t need to use datastores
Tables would be useful here

local Banned = {} 

Initiates a table to store the banned user ids

To ban a player

Banned[Player2.UserId] = true

To see if a player is banned

if Banned[plr.UserId] then
    plr:Kick("banned from server")
end
local banList = {}
--Use this VV to add players to the ban table.
table.insert(banList,tobanvariable.UserId) --Replace "tobanvariable" with your target variable.

function Check(plr)
	local inst = plr
	for i,v in pairs(banList) do
		if v.UserId == inst.UserId then
			inst:Kick("You have been banned from this server by an administrator..")
		end
	end
end
game:GetService("Players").PlayerAdded:Connect(Check)
1 Like

Is it good? In the last if is the ban :open_mouth:

Server Script:

---- ADMINS
local banList = {}
--Use this VV to add players to the ban table.
--Replace "tobanvariable" with your target variable.

function Check(plr)
	local inst = plr
	for i,v in pairs(banList) do
		if v.UserId == inst.UserId then
			inst:Kick("You have been banned from this server by an administrator..")
		end
	end
end
game:GetService("Players").PlayerAdded:Connect(Check)



local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
	
	Player.Chatted:Connect(function(message)
		if Player.TeamColor == BrickColor.new("Slime green") then
			for i,Player2 in pairs(Players:GetPlayers()) do
				if message == '.kick ' .. Player2.Name then
					print("The player name is ..." .. Player2.Name)
					Player2:Kick("You have been kicked by the owner.")
				end
			end
		end
		if Player.TeamColor == BrickColor.new("Slime green") then
			for i,Player2 in pairs(Players:GetPlayers()) do
				if message == '.warn ' .. Player2.Name then
					print("The player name is ..." .. Player2.Name)
					print("The administrator has given you a warning")
				end
			end
		end
		if Player.TeamColor == BrickColor.new("Slime green") then
			for i,Player2 in pairs(Players:GetPlayers()) do
				if message == '.ban ' .. Player2.Name then
					print("The player name is ..." .. Player2.Name)
					print("You have been banned by the administrator")
					-- How could i ban the player here?
					-- code to ban the player here:
					table.insert(banList,Player2.UserId)
				end
			end
		end
	end)
end)
--

You need to move the check function & player added to the bottom, then should work.

How exactly? I’m confused :frowning: like this?

image

---- ADMINS
local banList = {}
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)

	Player.Chatted:Connect(function(message)
		if Player.TeamColor == BrickColor.new("Slime green") then
			for i,Player2 in pairs(Players:GetPlayers()) do
				if message == '.kick ' .. Player2.Name then
					print("The player name is ..." .. Player2.Name)
					Player2:Kick("You have been kicked by the owner.")
				end
			end
		end
		if Player.TeamColor == BrickColor.new("Slime green") then
			for i,Player2 in pairs(Players:GetPlayers()) do
				if message == '.warn ' .. Player2.Name then
					print("The player name is ..." .. Player2.Name)
					print("The administrator has given you a warning")
				end
			end
		end
		if Player.TeamColor == BrickColor.new("Slime green") then
			for i,Player2 in pairs(Players:GetPlayers()) do
				if message == '.ban ' .. Player2.Name then
					print("The player name is ..." .. Player2.Name)
					print("You have been banned by the administrator")
					-- How could i ban the player here?
					-- code to ban the player here:
					table.insert(banList,Player2.UserId)
				end
			end
		end
	end)
end)
function Check(plr)
	local inst = plr
	for i,v in pairs(banList) do
		if v.UserId == inst.UserId then
			inst:Kick("You have been banned from this server by an administrator..")
		end
	end
end
game:GetService("Players").PlayerAdded:Connect(Check)
--
2 Likes

This works! :smiley: thanks you
How can I remove someone from the table? :scream:

You can remove items from a table via table.remove

1 Like

Oh i see like this? :smiley:

table.remove(banList, Player2.User.Id)

No, you would have to find the ID with table.find like this:

table.find(banList,ID)

And with that you could do this:

local toRemove = table.find(banList,ID)
table.remove(banList,toRemove)
1 Like

Hm, the way you have commands setup it’s kinda hard making it check for a table as you have no arguments variable. Could you try using a different command system?

1 Like

Of course, like which? :scream:

One second, I’ll get you a quick and easy command system. (Not very advanced, be aware.)

1 Like

Alright, you will have to add your rank checking system yourself as I’m not sure how you want it to be done, but here is a plain command system (with kick, ban, & unban)
This does NOT check if they have perms, you have to add it yourself

---- ADMINS
local banList = {}
local Players = game:GetService("Players")
local function ChatCMD(player, msg)
	if msg:sub(1,5):lower() == ".ban " then
		local target = Players:FindFirstChild(msg:sub(6))
		if target:IsA("Player") then
			table.insert(banList,target.UserId)
		else
			print("Not a valid player!")
		end
	elseif msg:sub(1,6):lower() == ".kick " then
		local target = Players:FindFirstChild(msg:sub(6))
		if target:IsA("Player") then
			target:Kick("You have been kicked.")
		else
			print("Not a valid player!")
		end
	elseif msg:sub(1,7):lower() == ".unban " then
		pcall(function()
			local target = table.find(banList,msg:sub(8)) --You will have to unban via their UserID not username.
			table.remove(banList,target)
		end)
	end
end
function Check(plr)
	local inst = plr
	for i,v in pairs(banList) do
		if v.UserId == inst.UserId then
			inst:Kick("You have been banned from this server by an administrator..")
		end
	end
end
game:GetService("Players").PlayerAdded:Connect(Check)
local function onPlayerAdded(player)
	player.Chatted:Connect(function (message)  ChatCMD(player, message) end)
end
--

Untested, please tell me whether it works or not.