Concatenate Problem

Currently i am working on CodePrime8’s admin panel

His Video

(20) Roblox - LMAG - How To Make Admin Panels for your game - YouTube

But i have a problem with it. I keep getting this error:

ServerScriptService.Admin:38: attempt to concatenate string with nil

in this code:

-- Admin panel script

local AdminRE = game:GetService("ReplicatedStorage").AdminRE

local Admins = {}

local Bans = {}

local DSS = game:GetService("DataStoreService")

local AdminData = DSS:GetDataStore("Admins")
local BanData = DSS:GetDataStore("Ban")

local function CheckAdmin(player)
	if player.Name == AdminData:GetAsync(player.UserId) then
		print("Is Admin")
		return true
	else
		print("Is Not An Admin")
		return false
	end
end

local function CheckBan(player)
	local BandID = player.UserId
	local BanReason = nil

	local success, err = pcall(function()
		BanReason = BanData:GetAsync(BandID)
	end)

	if success then
		if BanReason == "none" then
			-- leave empty
			
		else

			player:Kick("You are banned." .. player.Name .. "\n Reason: "..BanReason)
		end
	else
		error("Could not check ban for "..player.Name .. ":" .. player.UserId .. " - " .. err)
	end		

end

local function AdminCmd(Admin, cmd, Target, Reason)

	local Target = game.Players:FindFirstChild(Target)
	if CheckAdmin(Admin) then
		if cmd == "Kick" then
			print("You just send the Kick command to the server")
			Target:Kick("You have been kicked by an Admin")
		end
		if cmd == "Ban" then
			BanData:SetAsync(Target.UserId, "You have been banned by " .. Admin.Name)
			Target:Kick(Target.UserId, "You have been banned by " .. Admin.Name)
		end
		if cmd == "Freeze" then
			print("Freezing " .. Target.Name)
			game.Workspace:FindFirstChild(Target.Name).Head.Anchored = true
		end
		if cmd == "Unfreeze" then
			print("Unfreezing " .. Target.Name)
			game.Workspace:FindFirstChild(Target.Name).Head.Anchored = false
		end
	else
		BanData:SetAsync(Admin.UserId, "Attempted to invoke the Admin Remote Event")
		Admin:Kick("Kicked for attempting Admin Commands")
	end
end

game.Players.PlayerAdded:Connect(CheckBan)
game.Players.PlayerAdded:Connect(CheckAdmin)
AdminRE.OnServerEvent:Connect(AdminCmd)

but the problem is on this line:

player:Kick("You are banned." .. player.Name .. "\n Reason: "..BanReason)

Can anybody help me.

1 Like

I Might of fixed it by saying :

		if BanReason == "none" or BanReason == nil then

would this work

Try reading this other post… similar issue and fixed by checking for valid data before assigning a function to it:

all sorted thank you.
also just seen this sorry for the late reply

2 Likes