Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does my string turn out as a nil value after I fire the client?

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)

3 comments

0

Why not use the first parameter of OnServerEvent? Someone could just seem like another person and make them say rude stuff.

0

It's located in startergui. You would need access to their account to be their client. Also, fire server can only be called from the client and only fireclient can be called from the server.

0

Remove the "" in the remote.OnServerEvent:connect(function(,player,chat) line

1 answer

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)

1 comment

0

It prints out as an instance. It says "Instance".

This discussion is preserved as it was. New answers, comments, and votes are closed.