Roblox文本过滤始终失败,如何修复并实现重开输入窗口?
问题修复方案
核心错误原因
你的远程脚本中TextService:FilterStringAsync()的调用不符合Roblox API要求,该方法需要三个必填参数,但你只传入了待过滤文本,导致调用直接失败,哪怕输入正常词汇也会触发警告。
具体修复步骤
1. 修正远程脚本的文本过滤逻辑
Roblox FilterStringAsync的正确调用格式为:
TextService:FilterStringAsync(textToFilter, userId, textFilterContext)
过滤完成后,还需调用对应方法获取安全文本,不能直接使用原文本。修改后的远程脚本代码如下:
local editBoothRemote = game.ReplicatedStorage.EditBooth local TextService = game:GetService("TextService") -- 提前获取服务,避免重复调用 editBoothRemote.OnServerEvent:Connect(function(plr, boothText, imageId) if plr.ClaimedBooth.Value ~= nil then local booth = plr.ClaimedBooth.Value local topPart = booth.TopPart local imageLabel = topPart.SurfaceGui.ImageLabel local signText = topPart.SurfaceGui.boothTextLabel -- 验证图片ID(可选但推荐) local successImage, imageIdNum = pcall(tonumber, imageId) if successImage and imageIdNum then imageLabel.Image = "rbxassetid://" .. imageIdNum .. "&w=420&h=420" else warn("无效的图片ID") editBoothRemote:FireClient(plr) return end -- 文本过滤逻辑 local successFilter, result = pcall(function() -- 传入三个参数:待过滤文本、玩家ID、过滤上下文(公开场景用PublicChat) return TextService:FilterStringAsync(boothText, plr.UserId, Enum.TextFilterContext.PublicChat) end) if not successFilter then warn("文本过滤失败:" .. result) editBoothRemote:FireClient(plr) else -- 获取适合公开展示的过滤后文本 local filteredText = result:GetNonChatStringForBroadcast() signText.Text = filteredText end end end)
2. 修复本地脚本的语法错误
本地脚本最后一行的括号写错,需用end结束MouseButton1Click的连接函数:
local EditBoothRemote = game.ReplicatedStorage:WaitForChild("EditBooth") local editFrame = script.Parent.EditBooth EditBoothRemote.OnClientEvent:Connect(function() script.Parent.EditBooth.Visible = true end) editFrame.Confirm.MouseButton1Click:Connect(function() script.Parent.EditBooth.Visible = false local boothText= editFrame.BoothText.Text local imageId = editFrame.Image.Text EditBoothRemote:FireServer(boothText, imageId) end) -- 将原有的)替换为end
额外注意事项
- 确保
plr.ClaimedBooth是ObjectValue类型,且正确指向玩家的摊位对象 - 文本过滤上下文需匹配实际场景:私人内容用
Enum.TextFilterContext.PrivateChat,公开场景用PublicChat - 图片ID做数字验证可避免非法输入导致的加载失败问题
内容的提问来源于stack exchange,提问作者Aries
相关产品推荐
相关产品推荐

