How to move filtering text method to server within this system?

Hey you all. I’m making a shop for an obby game that basically sells modifiers that modify the game. For example: Remove all lasers. I want it so that the chat shows when a player buys a modifier, and that it makes sure to filter the result just in case.

The problem is that the local script says that the filtering of the text should be done on the server, but I don’t really know how to alter the system to reflect that.

I tried looking on the dev forums but I couldn’t find any specific way to do this.

Here is the local script:

--Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TextService = game:GetService("TextService")
local Chat = game:GetService("TextChatService")
local channel = Chat:WaitForChild("TextChannels"):WaitForChild("RBXSystem")

--Remote Events
local extraModifierChatEvent = ReplicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("OtherShopEvents"):WaitForChild("ExtraModifierEvents"):WaitForChild("DisplayEvents"):WaitForChild("ExtraModifierChatDisplayEvent")

--Variables
local plr = Players.LocalPlayer


local function generateSystemMsg(MsgDict: array)
	return '<font color ="#' ..MsgDict["Color"]..'"><font size="'..MsgDict["FontSize"]..'"><font face="'..MsgDict["Font"]..'">'..MsgDict["Text"]..'</font></font></font>'
end


--Get Info
extraModifierChatEvent.OnClientEvent:Connect(function(title)
	
	if typeof(title) ~= "string" then return end
	
	local filteredTitle = TextService:FilterStringAsync(title, plr.UserId)

	
	channel:DisplaySystemMessage(
		generateSystemMsg({

			Text = "[SERVER] "..tostring(filteredTitle),
			Font = "Gotham",
			Color = Color3.fromRGB(191, 0, 255):ToHex(),
			FontSize = "17"

		})
	)
	
end)

Here is the server script that relates to the local script:

Server Script
--Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")

--Modules
local CurrentModifiersModule = require(script:WaitForChild("CurrentExtraModifiers"))
local ModiferFunctionsModule = require(script:WaitForChild("ExtraModifierFunctions"))

--Remote Events
local ExtraModifierEvents = ReplicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("OtherShopEvents"):WaitForChild("ExtraModifierEvents")

local extraModifierChatEvent = ReplicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("OtherShopEvents"):WaitForChild("ExtraModifierEvents"):WaitForChild("DisplayEvents"):WaitForChild("ExtraModifierChatDisplayEvent")


local NoLasersEvent = ExtraModifierEvents:WaitForChild("NoLasers")
local InvertedEvent = ExtraModifierEvents:WaitForChild("Inverted")
local TimeFreezeEvent = ExtraModifierEvents:WaitForChild("TimeFreeze")

--Bindable Events
local displayEvent = ExtraModifierEvents:WaitForChild("DisplayEvents"):WaitForChild("DisplayBindableEvent")

--Variables
local isRound = ServerStorage:WaitForChild("IsRound")


--Prices
local prices = {
	
	["No Laser"] = 300,
	["Inverted"] = 200,
	["Time Freeze"] = 500
	
}

--Chat display function
local function chatDisplay(title)
	
	extraModifierChatEvent:FireAllClients(title)
	
end


--Purchase Events
--No lasers event
NoLasersEvent.OnServerEvent:Connect(function(plr, button, title)
	
	if not button:IsA("TextButton") then return end
	if typeof(title) ~= "string" then return end 
	
	
	if (isRound.Value == true) and (not table.find(CurrentModifiersModule.currentExtraModifiers, title)) then
		
		--Add modifer to current modifiers
		table.insert(CurrentModifiersModule.currentExtraModifiers, title)
		
		--Destroy Lasers
		ModiferFunctionsModule.NoLasers()
		
		--Make player pay for extra modifier
		local plrCash = plr:WaitForChild("leaderstats"):WaitForChild("Cash")
		if plrCash.Value >= prices["No Laser"] then
			plrCash.Value -= prices["No Laser"]
			
			displayEvent:Fire(title)
			chatDisplay(title)
			
		end
		
	end
	
end)


--Inverted event
InvertedEvent.OnServerEvent:Connect(function(plr, button, title)
	
	if not button:IsA("TextButton") then return end
	if typeof(title) ~= "string" then return end 


	if (isRound.Value == true) and (not table.find(CurrentModifiersModule.currentExtraModifiers, title)) then

		--Add modifer to current modifiers
		table.insert(CurrentModifiersModule.currentExtraModifiers, title)

		--Invert Colors
		ModiferFunctionsModule.Inverted()
		
		--Make player pay for extra modifier
		local plrCash = plr:WaitForChild("leaderstats"):WaitForChild("Cash")
		if plrCash.Value >= prices["Inverted"] then
			plrCash.Value -= prices["Inverted"]
			
			displayEvent:Fire(title)
			chatDisplay(title)
			
		end
		
	end

end)


--Time Freeze event
TimeFreezeEvent.OnServerEvent:Connect(function(plr, button, title)

	if not button:IsA("TextButton") then return end
	if typeof(title) ~= "string" then return end 


	if (isRound.Value == true) and (not table.find(CurrentModifiersModule.currentExtraModifiers, title)) then

		--Add modifer to current modifiers
		table.insert(CurrentModifiersModule.currentExtraModifiers, title)

		--Invert Colors
		ModiferFunctionsModule.TimeFreeze()

		--Make player pay for extra modifier
		local plrCash = plr:WaitForChild("leaderstats"):WaitForChild("Cash")
		if plrCash.Value >= prices["Time Freeze"] then
			plrCash.Value -= prices["Time Freeze"]
			
			displayEvent:Fire(title)
			chatDisplay(title)
			
		end

	end

end)

use a remotefunction and do text filtering with it.

Why don’t you just do it in the chat display function?

local PlayerService = game:GetService("Players")
local ChatService = game:GetService("Chat")
local function chatDisplay(title: string)
	local Player = PlayerService:GetPlayers()
	local FilteredTitle = Chat:FilterStringForBroadcast(title, Player[1]) --it doesn't really matter what player we choose, since its for broadcast.
	
	extraModifierChatEvent:FireAllClients(title)
end

(It worked) Would I do PlayerService:GetPlayers()[1] instead of Player[1] ?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.