Module script and server script replications fail, even if it works in studio

Hello, I am making a player based ban system. It does have an animation within it, but the only problem is the server ban saving. It does save to the module script with .Create(), but when the player joins once again, it won’t kick them.

I have tried testing this in studio with my userID already put in the module script, it works, but not in the main servers…

This is what is supposed to happen: (it works in studio when I pre put my userid in the table…)

When the .Create event is fired to save someone in the table, it actually works:


When they join back after that, they aren’t getting kicked. Ideas?

MODULE SCRIPT:

local Banned = {}

local ban = {}



function ban.Create(player)
	table.insert(Banned, player)
end

function ban.Remove(player)
	for i,v in pairs(Banned) do
		if v == player then
			table.remove(Banned, i)
		end
	end
end

function ban:GetContents()
	return Banned	
end

return ban

BAN HANDLER:

local DDS = game:GetService("DataStoreService")
local Key = DDS:GetDataStore("DataBan")

game.Players.PlayerAdded:Connect(function(plr)
	
	local success, result = pcall(function()
		return Key:GetAsync(plr.UserId)
	end)
	
	if success then
		if not result then return end
		if result then
				if result.Status == true then
			plr:Kick("\n\n == SKY EXPERIMENTS MODERATION SYSTEM == \n\n You have been terminated from this game. \n\n [Reason: " .. tostring(result.Reason) .. "] \n [Moderator: " .. tostring(result.Moderator) .. "] \n Time of Execution: [ " .. tostring(os.date("%c", os.time())) .. " ]\n\n If you think this was a mistake, please contact a Moderator+! \n")
			end
		end
	end
	
pcall(function()
	local contents = require(script.Bans)
	local content = contents:GetContents()
	for i,v in pairs(content) do
		if plr.UserId == v then
			plr:Kick("\n\n YOU HAVE BEEN SERVER BANNED!")
			end
		end
	end)
end)

BAN COMMAND ISSUER (the one who saves it into the table):

game.Players.PlayerAdded:Connect(function(plr)
	if plr.UserId == 2407693045 then
		plr.Chatted:Connect(function(msg)

			local cmd = msg:match(";%w*")
			local s = msg:gsub(";%w*", "")

			local name = s:match("%w*_%w*") or s:match("%w+")
			
			if cmd == ";ban" then
				for i,v in pairs(game.Players:GetPlayers()) do
					if string.lower(v.Name) == string.lower(tostring(name)) then
						game.ReplicatedStorage:WaitForChild("Broadcast"):FireAllClients(v.Name .. " has been issued a ban by the one and only, Pixelctrl. They have be fined 1000 gems for the sins they have done. They will be server banned in 30 seconds.", Color3.fromRGB(255, 170, 0))
						require(script.Parent:WaitForChild("Ban"):WaitForChild("Bans")).Create(v.UserId)
						pcall(function()
							v.leaderstats.Gems.Value = v.leaderstats.Gems.Value - 1000
						end)
						local term = coroutine.wrap(function()
							task.wait(30)
							v:Kick("\n\n SERVER BANNED BY PIXELCTRL")
							local bang = coroutine.wrap(function()
								local explosion = Instance.new("Sound")
								explosion.Volume = 4
								explosion.SoundId = "rbxassetid://4418405082"
								explosion.Parent = game.Workspace
								explosion:Play()
								explosion.Ended:Wait()
								explosion:Destroy()
							end)
							bang()
							for _, g in pairs(game.Players:GetPlayers()) do
								local remove = coroutine.wrap(function()
									local gui = Instance.new("ScreenGui")
									gui.Name = "Flash"
									local Frame = Instance.new("Frame")
									Frame.BackgroundColor3 = Color3.new(1,1,1)
									Frame.Size = UDim2.new(1,0,1,0)
									gui.ResetOnSpawn = false
									gui.IgnoreGuiInset = true
									Frame.Parent = gui
									Frame.ZIndex = 0
									Frame.BorderSizePixel = 0
									pcall(function()
										gui.Parent = g.PlayerGui
									end)
									task.wait(1)
									game:GetService("TweenService"):Create(Frame, TweenInfo.new(8), {Transparency = 1}):Play()
									task.wait(8)
									gui:Destroy()
								end)
								remove()
							end
						end)
						term()
					end
				end
			end
		end)
	end
end)

I have tried many solutions, none of them seem to work.

(p.s: no errors in console.)

1 Like

What if, the problem here, is the fact that the BanTable is not being saved? I think you would have to set a data table for it to save into the main script of the module.

Try printing the table in the function where you :GetContents(). If it is that the table doesn’t save, I think it’s best for the Module to put the values inside of the DataBan DDS, I think there’s a function that allows to find the DataStore and use it.

P.S: No, you cannot get an existing DataStore.

1 Like

The DDS ban system is for global bans… I have already tried printing the table with :GetContents, it worked. I’m making a server banning system that has its own table for each individual server.

1 Like