Hi im making a ban button following a tutorial like i always do and ive ran into a problem ive completed the script but it wont work and i dont know why heres the scripts:
Server script:
local versionNumber = 1
local banstorage = game.DataStoreService:GetService("Ban storage v"..versionNumber)
local admins = {
["1kLxfe"] = 1;
["spydercam500"] = 1;
["masry12"] = 1;
["Crazyloco04"] = 1;
["xShadowExiled"] = 1;
}
game.Players.PlayerAdded:Connect(function(player)
local previousData = banstorage:GetAsync(player.UserId)
if previousData == nil then
-- they dont have any data
banstorage:SetAsync(player.UserId, false)
--false equal to not banned true equaled to banned
else
if previousData == true then
--they are banned
player:Kick("You are banned LOOOL!")
else
print("Player is not banned!")
end
end
end)
game.ReplicatedStorage.Ban.OnServerEvent:Connect(function(player, victim)
if admins[player.Name] then
-- if they are a admin
local found = game.Players:FindFirstChild(victim)
if found then
banstorage:SetAsync(found.UserId, true)
found:Kick("You are banned LOOOL!")
end
end
end)
Local script:
local button = script.Parent
local textbox = script.Parent.Parent.Parent.PlayerNameBox
button.MouseButton1Click:Connect(function()
game.ReplicatedStorage.Ban:FireServer(textbox.Text)
end)
You’re attempting to combine “Ban storage v”, which is a string, with an integer in the server script. (I haven’t read through the entire script btw so I might have overlooked something).
I think ive maybe found the problem and its in the local script ok so i put a print to see what line it stopped at after the admin varible in the server script and it didnt work when i pressed the “ban” button
That means there must be a error in the local script
Ok well i found out that the local script was in the wrong button but it still doesnt work for some reason ive fixed the varible for the PlayerNameBox to and still doesnt work
Ok so this did solve the problem with the ban button itself but ive ran into another issue when the player rejoins there not banned after being banned so its more of a kick button then a ban button why is this?
if banstorage:GetAsync(player.UserId) then
-- kick player
end
Give this one a shot, replace the quoted part with this and lmk if it works, I’m on mobile and haven’t gotten the chance to test it yet. Also are there any errors?
local versionNumber = "1"
local banstorage = game:GetService("DataStoreService"):GetDataStore("Ban storage v"..versionNumber)
local admins = {
["1kLxfe"] = 1;
["spydercam500"] = 1;
["masry12"] = 1;
["Crazyloco04"] = 1;
["xShadowExiled"] = 1;
}
game.Players.PlayerAdded:Connect(function(player)
if banstorage:GetAsync(player.UserId) then
player:Kick("You are banned LOOOL!")
end
end)
game.ReplicatedStorage.Ban.OnServerEvent:Connect(function(player, victim)
if admins[player.Name] then
-- if they are a admin
local found = game.Players:FindFirstChild(victim)
if found then
banstorage:SetAsync(found.UserId, true)
found:Kick("You are banned LOOOL!")
end
end
end)
Here’s what I have now, this works for me.
Let me know how it goes