But on part that checks if the player is banned, here it is:
local DataStore = game:GetService("DataStoreService"):GetDataStore("BannedDataStore")
game.Players.PlayerAdded:Connect(function(plr)
local banStatus = DataStore:GetAsync("bans_"..tostring(plr.UserId))
if banStatus then
plr:Kick("You have been banned.")
end
end)
Wait where do I put that and where do I put the other script, here is the other part of the ban script then you tell me what I need to put where because i’m so confused rn
local DataStoreService = game:GetService("DataStoreService");
local DataStore = DataStoreService:GetDataStore("BannedDataStore");
game.Players.PlayerAdded:Connect(function(player)
local boolval = Instance.new("BoolValue", player)
local variable = DataStore:GetAsync(player.UserId)
print(variable)
boolval.Value = DataStore:GetAsync(player.UserId) or false
if boolval.Value == true then
player:Kick("Banned.")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
DataStore:SetAsync(player.UserId, player:FindFirstChild("Value").Value)
end)
local DataStore = game:GetService("DataStoreService"):GetDataStore("BannedDataStore")
game.Players.PlayerAdded:Connect(function(plr)
local banStatus = DataStore:GetAsync("bans_"..tostring(plr.UserId))
if banStatus then
plr:Kick("You have been banned.")
end
end)
game.ReplicatedStorage.BanTesting.OnServerEvent:Connect(function(player, userid) -- Presuming this is a userid
print(userid)
DataStore:SetAsync("bans_"..tostring(userid), true)
end)
I printed what it said and now it is showing up as nil here is the code
game.Players.PlayerAdded:Connect(function(plr)
local banStatus = DataStore:GetAsync("bans_"..tostring(plr.UserId))
if banStatus then
plr:Kick("You have been banned.")
end
end)
game.ReplicatedStorage.BanTesting.OnServerEvent:Connect(function(player, userid) -- Presuming this is a userid
local userId2 = userid.UserId
print(userId2)
DataStore:SetAsync("bans_"..tostring(userId2), true)
end)
you sent a username, right? you gotta use :GetPlayerFromTextAsync() to get the actual player object
game.Players.PlayerAdded:Connect(function(plr)
local banStatus = DataStore:GetAsync("bans_"..tostring(plr.UserId))
if banStatus then
plr:Kick("You have been banned.")
end
end)
game.ReplicatedStorage.BanTesting.OnServerEvent:Connect(function(player, userid) -- Presuming this is a userid
local player = game.Players:GetPlayerFromTextAsync(userid)
local userId2 = player.UserId
print(userId2)
DataStore:SetAsync("bans_"..tostring(userId2), true)
end)
I’m sorry w h a t, that’s not a valid function of the Players service
game.Players.PlayerAdded:Connect(function(plr)
local banStatus = DataStore:GetAsync("bans_"..plr.UserId)
if banStatus then
plr:Kick("You have been banned.")
end
end)
game.ReplicatedStorage.BanTesting.OnServerEvent:Connect(function(player, userid) -- Presuming this is a userid
print(userid)
DataStore:SetAsync("bans_"..tostring(userid), true)
end)
Also there are a couple of mistypo/capitalization errors
plr.UserId returns back a string value, no need to convert it into a string
game.Players.PlayerAdded:Connect(function(plr)
local banStatus = DataStore:GetAsync("bans_"..plr.UserId)
if banStatus then
plr:Kick("You have been banned.")
end
end)
game.ReplicatedStorage.BanTesting.OnServerEvent:Connect(function(player, playerName)
local banTarget = game.Players:FindFirstChild(playerName)
local userid = banTarget.UserId
print(userid)
DataStore:SetAsync("bans_"..userid, true)
end)
Side note, you should check if there’s at least a valid banTarget in the game, otherwise it’ll return back as nil if the Player enters a incorrect name
game.Players.PlayerAdded:Connect(function(plr)
local banStatus = DataStore:GetAsync("bans_"..plr.UserId)
if banStatus then
plr:Kick("You have been banned.")
end
end)
game.ReplicatedStorage.BanTesting.OnServerEvent:Connect(function(player, playerName)
local banTarget = game.Players:FindFirstChild(playerName)
print(banTarget)
if banTarget then
local userid = banTarget.UserId
print(userid)
DataStore:SetAsync("bans_"..userid, true)
end
end)