Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
popeeyy 493 Moderation Voter
6 years ago

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)
0
Why not use the first parameter of OnServerEvent? Someone could just seem like another person and make them say rude stuff. hiimgoodpack 2009 — 6y
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. popeeyy 493 — 6y
0
Remove the "_" in the remote.OnServerEvent:connect(function(_,player,chat) line UltraUnitMode 419 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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)
0
It prints out as an instance. It says "Instance". popeeyy 493 — 6y
Ad

Answer this question