ข้อความที่จำกัดอัตรา

*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่

คำแนะนำนี้แสดงวิธีการกำหนดขีดจำกัดอัตรา 1 นาทีบนฟิลด์ข้อความที่อนุญาตให้ผู้เล่นโพสต์บันทึกลงในกระดานข่าวของชุมชน

เพิ่มสิ่งต่อไปนี้ลงใน Script ใน ServerScriptService:

Server

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- สร้าง RemoteEvent สำหรับการสื่อสาร
local postNoteEvent = Instance.new("RemoteEvent")
postNoteEvent.Name = "PostNoteEvent"
postNoteEvent.Parent = ReplicatedStorage
-- ขีดจำกัดอัตราหนึ่งบันทึกต่อหนึ่งนาทีต่อผู้เล่น
local COOLDOWN_TIME = 60 -- เวลาเป็นวินาที
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
-- จัดการคำขอโพสต์ด้วยขีดจำกัดอัตราและการกรองข้อความ
postNoteEvent.OnServerEvent:Connect(function(player, noteData)
local canPost, cooldown = canPlayerPost(player)
if not canPost then
postNoteEvent:FireClient(player, "cooldown", math.ceil(cooldown))
return
end
-- ข้อความทั้งหมดที่แชร์แบบสาธารณะต้องผ่านการกรองข้อความ
local filterResult = getFilterResult(noteData.text, player.UserId)
if filterResult then
local success, filteredText = pcall(function()
return filterResult:GetNonChatStringForBroadcastAsync()
end)
if success then
-- สร้างบันทึก
local note = {
text = filteredText
}
-- อัปเดตเวลาที่โพสต์ล่าสุด
lastPostTime[player.UserId] = tick()
-- ส่งการตอบสนองความสำเร็จ
postNoteEvent:FireClient(player, "success", note)
-- กระจายบันทึกใหม่ไปยังผู้เล่นทุกคน
postNoteEvent:FireAllClients("newNote", note)
else
warn("เกิดข้อผิดพลาดในการกรองข้อความ!")
end
end)
-- ทำความสะอาดเมื่อผู้เล่นออกจากเกม
Players.PlayerRemoving:Connect(function(player)
lastPostTime[player.UserId] = nil
end)
©2026 Roblox Corporation. Roblox, โลโก้ Roblox และ Powering Imagination เป็นส่วนหนึ่งของเครื่องหมายการค้าที่จดทะเบียน และไม่ได้จดทะเบียนของเราในสหรัฐฯ และประเทศอื่นๆ