Problem Datastore

Why is this erroring.

local SSS = game:GetService("ServerScriptService")

local MyModule = require(SSS:FindFirstChild("AdminSystemConfig").ModuleScript)
local DSS = game:GetService("DataStoreService"):GetDataStore("AdminPanel")

local Pban = {

}



-- Serverban Code

game.ReplicatedStorage["Admin System"].Pban.OnServerEvent:Connect(function(Player, plrToBan, Reason)
	if Player:GetRankInGroup(MyModule.GroupID) >= MyModule.BanID then
		if game.Players:FindFirstChild(plrToBan) then
			DSS:SetAsync(plrToBan.UserId.."-BAN", plrToBan.UserId)
			game:GetService("Players"):FindFirstChild(plrToBan):Kick("PERMBAN | ".. Reason)
			Player.PlayerGui["Admin Panel"]:Destroy()

	else 
			game.Players:WaitForChild(plrToBan) 
			DSS:SetAsync(plrToBan.UserId.."-BAN", plrToBan.UserId)
			game:GetService("Players"):FindFirstChild(plrToBan):Kick("PERMBAN | ".. Reason)	
			Player.PlayerGui["Admin Panel"]:Destroy()
		end		
end
end)

-- Unban Code
--game.ReplicatedStorage["Admin System"].UnPermBan.OnServerEvent:Connect(function(Player, plrToUnban)
--	if Player:GetRankInGroup(MyModule.GroupID) > MyModule.UnbanID then
	--local userID = game.Players:GetUserIdFromNameAsync(plrToUnban)
--		local index = table.find(Pban, userID) 
	--	table.remove(Pban, index) 
	--	Player.PlayerGui["Admin Panel"]:Destroy()

--	else
--		Player:Kick("Anti Exploit Protocol")
--		end
--end)

-- Serverban Handler
game.Players.PlayerAdded:Connect(function(plr)
	if DSS:GetAsync(plr.UserId.."-BAN") then
		plr:Kick("GAMEBAN | Je bent Permanent Verbannen van deze server, dit betekend dat je geen toegang meer hebt tot de game, klopt dit niet maak een ticket in de Community Server.")
	end
end)

Error:

1 Like

Can you show the code that fires the ban remote

Yeah

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage["Admin System"].Pban:FireServer(script.Parent.Parent.Parent.BanFrame.Persoon.Text, script.Parent.Parent.Parent.BanFrame.Reden.Text)
end)

Ok the code doesnt work because your attempting to get the UserId from a string not the actual player here

Replace plrToBan.UserId with game.Players[plrToBan].UserId .

local SSS = game:GetService("ServerScriptService")

local MyModule = require(SSS:FindFirstChild("AdminSystemConfig").ModuleScript)
local DSS = game:GetService("DataStoreService"):GetDataStore("AdminPanel")

local Pban = {

}



-- Serverban Code

game.ReplicatedStorage["Admin System"].Pban.OnServerEvent:Connect(function(Player, plrToBan, Reason)
	if Player:GetRankInGroup(MyModule.GroupID) >= MyModule.BanID then
		if game.Players:FindFirstChild(plrToBan) then
			DSS:SetAsync(game.Players[plrToBan].UserId)
			game:GetService("Players"):FindFirstChild(plrToBan):Kick("PERMBAN | ".. Reason)
			Player.PlayerGui["Admin Panel"]:Destroy()

	else 
			game.Players:WaitForChild(plrToBan) 
			DSS:SetAsync(game.Players[plrToBan].UserId)
			game:GetService("Players"):FindFirstChild(plrToBan):Kick("PERMBAN | ".. Reason)	
			Player.PlayerGui["Admin Panel"]:Destroy()
		end		
end
end)

-- Unban Code
--game.ReplicatedStorage["Admin System"].UnPermBan.OnServerEvent:Connect(function(Player, plrToUnban)
--	if Player:GetRankInGroup(MyModule.GroupID) > MyModule.UnbanID then
	--local userID = game.Players:GetUserIdFromNameAsync(plrToUnban)
--		local index = table.find(Pban, userID) 
	--	table.remove(Pban, index) 
	--	Player.PlayerGui["Admin Panel"]:Destroy()

--	else
--		Player:Kick("Anti Exploit Protocol")
--		end
--end)

-- Serverban Handler
game.Players.PlayerAdded:Connect(function(plr)
	if DSS:GetAsync(plr.UserId.."-BAN") then
		plr:Kick("GAMEBAN | Je bent Permanent Verbannen van deze server, dit betekend dat je geen toegang meer hebt tot de game, klopt dit niet maak een ticket in de Community Server.")
	end
end)

This?

Yes that should work

sasasasasas

I have now a new error look to this error:

This is the code in line 17.

			DSS:SetAsync(game.Players[plrToBan].UserId)

Oh yeah i just noticed that you removed .."-BAN", plrToBan.UserId in the SetAsync function.

Heres the fixed script:

local SSS = game:GetService("ServerScriptService")

local MyModule = require(SSS:FindFirstChild("AdminSystemConfig").ModuleScript)
local DSS = game:GetService("DataStoreService"):GetDataStore("AdminPanel")

local Pban = {

}



-- Serverban Code

game.ReplicatedStorage["Admin System"].Pban.OnServerEvent:Connect(function(Player, plrToBan, Reason)
	if Player:GetRankInGroup(MyModule.GroupID) >= MyModule.BanID then
		if game.Players:FindFirstChild(plrToBan) then
			DSS:SetAsync(tostring(game.Players[plrToBan].UserId).."-BAN", game.Players[plrToBan].UserId)
			game:GetService("Players"):FindFirstChild(plrToBan):Kick("PERMBAN | ".. Reason)
			Player.PlayerGui["Admin Panel"]:Destroy()

	else 
			game.Players:WaitForChild(plrToBan) 
			DSS:SetAsync(tostring(game.Players[plrToBan].UserId).."-BAN", game.Players[plrToBan].UserId)
			game:GetService("Players"):FindFirstChild(plrToBan):Kick("PERMBAN | ".. Reason)	
			Player.PlayerGui["Admin Panel"]:Destroy()
		end		
end
end)

-- Unban Code
--game.ReplicatedStorage["Admin System"].UnPermBan.OnServerEvent:Connect(function(Player, plrToUnban)
--	if Player:GetRankInGroup(MyModule.GroupID) > MyModule.UnbanID then
	--local userID = game.Players:GetUserIdFromNameAsync(plrToUnban)
--		local index = table.find(Pban, userID) 
	--	table.remove(Pban, index) 
	--	Player.PlayerGui["Admin Panel"]:Destroy()

--	else
--		Player:Kick("Anti Exploit Protocol")
--		end
--end)

-- Serverban Handler
game.Players.PlayerAdded:Connect(function(plr)
	if DSS:GetAsync(tostring(plr.UserId).."-BAN") then
		plr:Kick("GAMEBAN | Je bent Permanent Verbannen van deze server, dit betekend dat je geen toegang meer hebt tot de game, klopt dit niet maak een ticket in de Community Server.")
	end
end)

(i also added tostring() in the SetAsync function because it would probably error if you would try to combine a UserId and string)

Uhm i have the same error.

Edited the script is should work now.

Uhm this doesnt work. Line 18.

It looks like the reason is empty, can you try typing something into the reason textbox then fire the remote?

Don’t works, i have the reason gived.

Code
			game:GetService("Players"):FindFirstChild(plrToBan):Kick("PERMBAN | ".. Reason)

The error message suggests that the “Reason” variable might be nil. To fix this error, you can add a check to ensure that the “Reason” variable is not nil before concatenating it with the string. You can do this by modifying the line as follows:

game:GetService("Players"):FindFirstChild(plrToBan):Kick("PERMBAN | ".. (Reason or ""))

This will ensure that if the “Reason” variable is nil, it will default to an empty string and the concatenation will not result in an error.

Alright thanks, this works now!

Can you maybe help me with the reason to save?

@Xacima The ban check doesn’t work, it bans me now if i fire the script, but if i rejoin i can simply join the game without kick.

Check Script:

game.Players.PlayerAdded:Connect(function(plr)
	if DSS:GetAsync(tostring(plr.UserId.."-BAN")) then
		plr:Kick("GAMEBAN | Je bent Permanent Verbannen van deze server, dit betekend dat je geen toegang meer hebt tot de game, klopt dit niet maak een ticket in de Community Server.")
		end
end)

If you want to save the reason, you can store it as a string in your datastore.

local Table = {Reason = YOUR_REASON}

Then, you can save the table to the player key.

Here’s an updated version of how you can use the GetAsync function properly, this should also solve the issue that you’re having.

local Ok, Result = pcall(function()
	return DSS:GetAsync(tostring(plr.UserId.."-BAN"))
end)

if (Ok) then
	-- // If the call was successful
	if (Result) then
		plr:Kick("GAMEBAN | Je bent Permanent Verbannen van deze server, dit betekend dat je geen toegang meer hebt tot de game, klopt dit niet maak een ticket in de Community Server.")
		-- If the player has any data, kick them
	else
		-- // Player does not have any data
	end
else
	-- // Unable to get the player's data
end