Hello! I want to make a mute command with a timer and datastore so it prevents players from leaving to bypass the mute.
Here is what I have so far, although I have no idea how to implement a timer, do I just used task.wait() or is it more complicated?
local TextChatService = game:GetService("TextChatService")
local function muteUserId(mutedUserId)
-- listen for future TextSources
TextChatService.DescendantAdded:Connect(function(child)
if child:IsA("TextSource") then
if child.UserId == mutedUserId then
child.CanSend = false
end
end
end)
-- mute any current TextSources
for _, child in TextChatService:GetDescendants() do
if child:IsA("TextSource") then
if child.UserId == mutedUserId then
child.CanSend = false
end
end
end
end
local function unmuteUserId(mutedUserId)
-- listen for future TextSources
TextChatService.DescendantAdded:Connect(function(child)
if child:IsA("TextSource") then
if child.UserId == mutedUserId then
child.CanSend = true
end
end
end)
-- mute any current TextSources
for _, child in TextChatService:GetDescendants() do
if child:IsA("TextSource") then
if child.UserId == mutedUserId then
child.CanSend = true
end
end
end
end
local muteremote = game:GetService("ReplicatedStorage").Remotes.Mute
muteremote.OnServerEvent:Connect(function(player, mode)
local char = player.Character
player:SetAttribute("Muted", false)
if mode == "Mute" and player:GetAttribute("Muted") == false then
player:SetAttribute("Muted", true)
muteUserId(player)
--timer here
unmuteUserId(player)
elseif mode == "Unmute" and player:GetAttribute("Muted") == true then
player:SetAttribute("Muted", false)
unmuteUserId(player)
end
end)
Helps are appreciated!