Bu örnek, oyuncuların bir topluluk ilan panosuna not bırakmasına izin veren bir metin giriş alanında 1 dakikalık bir hız limiti nasıl uygulanacağını göstermektedir.
ServerScriptService içinde bir Script'e aşağıdakileri ekleyin:
Server
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- İletişim için RemoteEvent yarat
local postNoteEvent = Instance.new("RemoteEvent")
postNoteEvent.Name = "PostNoteEvent"
postNoteEvent.Parent = ReplicatedStorage
-- Her oyuncu için dakikada bir not gönderme sınırı
local COOLDOWN_TIME = 60 -- Zaman saniye cinsinden
local lastPostTime = {}
local function canPlayerPost(player)
local userId = player.UserId
local currentTime = tick()
if lastPostTime[userId] then
local timeSinceLastPost = currentTime - lastPostTime[userId]
if timeSinceLastPost < COOLDOWN_TIME then
return false, COOLDOWN_TIME - timeSinceLastPost
end
end
return true, 0
end
-- Hız limiti ve metin filtreleme ile gönderim isteklerini işleme
postNoteEvent.OnServerEvent:Connect(function(player, noteData)
local canPost, cooldown = canPlayerPost(player)
if not canPost then
postNoteEvent:FireClient(player, "cooldown", math.ceil(cooldown))
return
end
-- Kamuya açık olarak paylaşılacak tüm metinler bir metin filtresinden geçmelidir
local filterResult = getFilterResult(noteData.text, player.UserId)
if filterResult then
local success, filteredText = pcall(function()
return filterResult:GetNonChatStringForBroadcastAsync()
end)
if success then
-- Notu oluştur
local note = {
text = filteredText
}
-- Son gönderim zamanını güncelle
lastPostTime[player.UserId] = tick()
-- Başarı yanıtını gönder
postNoteEvent:FireClient(player, "success", note)
-- Yeni notu tüm oyunculara yayınla
postNoteEvent:FireAllClients("newNote", note)
else
warn("Metin filtreleme hatası!")
end
end)
-- Oyuncu ayrıldığında temizleme yap
Players.PlayerRemoving:Connect(function(player)
lastPostTime[player.UserId] = nil
end)