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

RemoteEven: FireClient can only be called from the server?

How fix this? //FireClient can only be called from the server\

Game Explorer: https://gyazo.com/c1a27b624962cc329141890a46dcdac7

Script -

game.Players.PlayerAdded:connect(function(player)
	local ChatBox = game.ReplicatedStorage.ChatHandler.ChatHistory:Clone()
	ChatBox.Parent = player.PlayerGui:WaitForChild("GameGui").Chat
	ChatBox.Name = "ChatBox"
end)

Script -

game.ReplicatedStorage.ChatHandler.NewMsg.OnClientEvent:connect(function() 
	--// My LuaScript
end)

workspace.ChildAdded:connect(function(object)
	local NewPlayer = game.Players:playerFromCharacter(object)
	if NewPlayer then
		--// My LuaScript
	end	
end)

LocalScript -

local plr = game.Players.LocalPlayer
local chat = game.ReplicatedStorage.ChatHandler.ChatHistory
local last

function newChat(msg,plr)
	--// My LuaScript
end

game.Players.LocalPlayer.Chatted:connect(function(msg)
	newChat(msg, plr) print("newChat")
	game.ReplicatedStorage.ChatHandler.NewMsg:FireClient(plr, msg) print("FireClient")
end)

In Studio: https://gyazo.com/fb48f2bc69b44d253d821a93a637511f In Game: https://gyazo.com/5bf329bc9840f44429119ca6acb2ecb7

1 comment

0

Remember, the Client is every Player in the game. The Server is the one thing that connects all the Players together.

1 answer

✓ Accepted answer

You're getting it mixed up. Instead of :FireClient(), do :FireServer(), and instead of OnClientEvent, do OnServerEvent.

localscript:

local plr = game.Players.LocalPlayer
local chat = game.ReplicatedStorage.ChatHandler.ChatHistory
local last

function newChat(msg,plr)
    --// My LuaScript
end

game.Players.LocalPlayer.Chatted:connect(function(msg)
    newChat(msg, plr) print("newChat")
    game.ReplicatedStorage.ChatHandler.NewMsg:FireServer(msg) 
    print("FireClient")
end)

server script:

game.ReplicatedStorage.ChatHandler.NewMsg.OnServerEvent:connect(function() 
    --// My LuaScript
end)

workspace.ChildAdded:connect(function(object)
    local NewPlayer = game.Players:playerFromCharacter(object)
    if NewPlayer then
        --// My LuaScript
    end 
end)

Also, with filtering enabled the server can't access the client's guis so you'll have to use :FireClient to tell the client to change the guis.

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