Hello everyone! I am trying to make a mute command for my game and the code does not seem to work as it should, when i added the mute command, my other commands stopped working. Any help would be appriciated!
game.Players.PlayerAdded:Connect(function(player)
local DataStoreService = game:GetService("DataStoreService")
local BanStore = DataStoreService:GetDataStore("Save","Ban")
local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner"):WaitForChild ("ChatService"))
local Channel = ChatService:GetChannel("All")
local success, errorMessage = pcall(function()
local ban = BanStore:GetAsync(player.UserId)
if ban.Banned == true then
player:Kick("Banned, reason: "..ban.BanReason)
end
end)
if success then
print("Successful load")
else
warn(errorMessage)
end
if player.UserId ~= 3352681354 then return end
player.Chatted:connect(function(message)
local words = string.split(message," ")
local prefix = ":"
if string.find(words[1],prefix) ~= 1 then return end
words[1] = string.split(words[1],prefix)[2]
if words[1] == "mute" then
local target
for _,p in pairs(game.Players:GetPlayers()) do
local playerName = string.lower(p.Name)
if string.match(playerName,string.lower(words[2])) then
target = p
break
end
end
if target then
Channel:MuteSpeaker(target)
end
if words[1] == "kill" then
local target
for _,p in pairs(game.Players:GetPlayers()) do
local playerName = string.lower(p.Name)
if string.match(playerName,string.lower(words[2])) then
target = p
break
end
end
if target.Character then
target.Character.Humanoid.Health = 0
end
elseif words[1] == "kick" then
local target
for _,p in pairs(game.Players:GetPlayers()) do
local playerName = string.lower(p.Name)
if string.match(playerName,string.lower(words[2])) then
target = p
break
end
end
local reason = words
for rep = 1, 2 do
table.remove(reason,1)
end
reason = table.concat(reason," ")
if target then target:Kick(reason) end
if player:GetRankInGroup(14196783) >= 248 then return end
elseif words[1] == "ban" then
local target
for _,p in pairs(game.Players:GetPlayers()) do
local playerName = string.lower(p.Name)
if string.match(playerName,string.lower(words[2])) then
target = p
if target == player then
return
end
break
end
end
local targetId
if not target then
local _,e = pcall(function()
targetId = game.Players:GetUserIdFromNameAsync(words[2])
end)
local _,e2 = pcall(function()
game.Players:GetNameFromUserIdAsync(tonumber(words[2]))
end)
if e and e2 then
return
end
if not e2 and e then
... (62 lines left)