I did 2 scripts. One in StarterGui and one in SSS. The one in SSS filters a sting and prints it out correctly. But, when I fire the client it says "nil" when it comes out. Help?
SSS:
local rs = game:GetService("ReplicatedStorage") local remote = rs:WaitForChild("Filter") remote.OnServerEvent:connect(function(_,player,chat) local chat= game:GetService("Chat"):FilterStringForBroadcast(chat,player) print(chat) print(player) remote:FireClient(player,chat) end)
StarterGui
script.Parent.MouseButton1Click:connect(function() player= game.Players.LocalPlayer local chat= script.Parent.Parent.NewName.Text game.ReplicatedStorage.Filter:FireServer(player,chat) end) game.ReplicatedStorage.Filter.OnClientEvent:connect(function(player,chat) print(chat) script.Parent.Text=chat end)
OnClientEvent
does not pass the player it's fired to as its first argument since it's pretty pointless. If you call FireClient()
with two arguments, OnClientEvent
should have one. In your line game.ReplicatedStorage.Filter.OnClientEvent:connect(function(player,chat)
, player
would actually be the chat
argument that you passed, chat
would be nil.
script.Parent.MouseButton1Click:connect(function() local player = game.Players.LocalPlayer local chat= script.Parent.Parent.NewName.Text game.ReplicatedStorage.Filter:FireServer(player,chat) end) game.ReplicatedStorage.Filter.OnClientEvent:connect(function(chat) print(chat) script.Parent.Text=chat end)