so i made a block building game while i was playing it with some random ppl and one guy was annoyed by me so what he did… ( theres a sign block that u can input any text ) was make the sign block text swearing at me??? i instanty banned him and searched for results i found some filter and broadcast thing but it returns as error pls help:
script.Parent.PartPlaced.OnServerEvent:Connect(function(player, Face, Target, SignText)
local character = player.Character
if character and character:FindFirstChild("HumanoidRootPart") then
local Block = game.ReplicatedStorage.Block14:Clone()
Block.SurfaceGui.TextLabel.Text = SignText
if Face == Enum.NormalId.Top then
Block.Position = Target.Position + Vector3.new(0, 4, 0)
Block.SurfaceGui.Face = Face
elseif Face == Enum.NormalId.Left then
Block.Position = Target.Position + Vector3.new(-4, 0, 0)
Block.SurfaceGui.Face = Face
elseif Face == Enum.NormalId.Right then
Block.Position = Target.Position + Vector3.new(4, 0, 0)
Block.SurfaceGui.Face = Face
elseif Face == Enum.NormalId.Bottom then
Block.Position = Target.Position + Vector3.new(0, -4, 0)
Block.SurfaceGui.Face = Face
elseif Face == Enum.NormalId.Back then
Block.Position = Target.Position + Vector3.new(0, 0, 4)
Block.SurfaceGui.Face = Face
elseif Face == Enum.NormalId.Front then
Block.Position = Target.Position + Vector3.new(0, 0, -4)
Block.SurfaceGui.Face = Face
end
Block.Parent = workspace.Blocks
end
end)
script.Parent.PartPlaced.OnServerEvent:Connect(function(player, Face, Target, SignText)
local character = player.Character
if character and character:FindFirstChild("HumanoidRootPart") then
local Block = game.ReplicatedStorage.Block14:Clone()
local filterResult
local success, errorMessage = pcall(function()
filterResult = game:GetService("TextService"):FilterStringAsync(SignText, player.UserId)
end)
if success then
Block.SurfaceGui.TextLabel.Text = filterResult:GetNonChatStringForBroadcastAsync()
else
--
end
if Face == Enum.NormalId.Top then
Block.Position = Target.Position + Vector3.new(0, 4, 0)
Block.SurfaceGui.Face = Face
elseif Face == Enum.NormalId.Left then
Block.Position = Target.Position + Vector3.new(-4, 0, 0)
Block.SurfaceGui.Face = Face
elseif Face == Enum.NormalId.Right then
Block.Position = Target.Position + Vector3.new(4, 0, 0)
Block.SurfaceGui.Face = Face
elseif Face == Enum.NormalId.Bottom then
Block.Position = Target.Position + Vector3.new(0, -4, 0)
Block.SurfaceGui.Face = Face
elseif Face == Enum.NormalId.Back then
Block.Position = Target.Position + Vector3.new(0, 0, 4)
Block.SurfaceGui.Face = Face
elseif Face == Enum.NormalId.Front then
Block.Position = Target.Position + Vector3.new(0, 0, -4)
Block.SurfaceGui.Face = Face
end
Block.Parent = workspace.Blocks
end
end)
If you’re testing this in Studio, that’s why it doesn’t filter. Studio lacks the chat filter, and this seems to apply to TextService methods too.
I ran the same piece of code, once in Studio, once in the Roblox server-sided developer console:
print(game:GetService("TextService"):FilterStringAsync(--[[F word and S word as a string]], --[[my UserId]], Enum.TextFilterContext.PublicChat):GetNonChatStringForBroadcastAsync())
In Studio, I got unfiltered text. In Roblox servers, it came back as hashtags. Please remember to use a pcall. I did not since it was a one line test.
Try testing it in game servers and see if the issue still persists.
pcall basically just catches errors. If you use it right in this context, you can catch any errors that could occur during the filter process.
There’s a common misconception that anything ending in Async needs a pcall. Some things that end in Async do, because they are asynchronous network requests that can fail, but don’t always fail. I can’t remember if TextService’s filter methods are part of that group which need pcalls, but there’s no harm in doing so.
I’d actually recommend an xpcall for easier handling.
local _, filtered = xpcall(function()
return TextService:FilterStringForBroadcast(text, userId, Enum.TextFilterContext.PublicChat):GetNonChatStringForBroadcastAsync()
end, function(_err)
--you can filter text yourself here. This code will only run if the previous code fails.
return filteredText
end)
--now, no matter what, you will always have some kind of filtered text.