I created a ban system, however, when I chat the command, it doesn’t work.
Everything seems correct, but it doesn’t work, with no errors. Heres the script:
local Players = game:GetService("Players")
local GroupId = 11941815
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("HGS_Bans902938948373")
game.Players.PlayerAdded:Connect(function(Player)
local BanFolder = Instance.new("Folder", Player)
BanFolder.Name = "BanValue"
local BanValue = Instance.new("BoolValue", BanFolder)
BanValue.Name = "Ban"
Player.Chatted:Connect(function(Message)
if Message[1] == "/ban" then
if Message[2] then
local FoundPlayer
for Index, Plr in ipairs(game.Players:GetPlayers()) do
if (Plr.Name:sub(1,#Message[2]):lower() == Message[2]:lower()) then
FoundPlayer = Plr
end
end
FoundPlayer:WaitForChild("PlayerGui").BanScreen.Enabled = true
BanValue.Value = true
DataStore:SetAsync(Player.UserId, BanValue.Value)
end
end
end)
end)
Copy this and try this code in studio. I hope you have understood what the guys from above are saying about string.split
if you still don’t understand try this fixed code:
local Players = game:GetService("Players")
local GroupId = 11941815
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("HGS_Bans902938948373")
game.Players.PlayerAdded:Connect(function(Player)
local BanFolder = Instance.new("Folder", Player)
BanFolder.Name = "BanValue"
local BanValue = Instance.new("BoolValue", BanFolder)
BanValue.Name = "Ban"
Player.Chatted:Connect(function(Message)
local SplitedMessage = Message:split(" ")
if SplitedMessage[1] == "/ban" then
if SplitedMessage[2] then
local FoundPlayer
for Index, Plr in ipairs(game.Players:GetPlayers()) do
if (Plr.Name:sub(1,#SplitedMessage[2]):lower() == SplitedMessage[2]:lower()) then
FoundPlayer = Plr
end
end
FoundPlayer:WaitForChild("PlayerGui").BanScreen.Enabled = true
BanValue.Value = true
DataStore:SetAsync(Player.UserId, BanValue.Value)
end
end
end)
end)