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)