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

Onclient event can only be used on the client why this happen?

Asked by 3 years ago
Edited 3 years ago

Script 1 ServerScript Service

local GroupId = 9852197 local MiniumRankIdForJoinMessage = 255

game.Players.PlayerAdded:Connect(function(Player) if Player:GetRankInGroup(GroupId) >= MiniumRankIdForJoinMessage then game.ReplicatedStorage.PlayerJoinEvent:FireAllClients(Player.Name, Player.UserId) end end)

Script 2 StarterGui

local StarterGUI = game:GetService("StarterGui")

local function SendNotification(Title, Text, Icon) StarterGUI:SetCore("SendNotification", { Title = Title, Text = Text, Icon = Icon }) end

game.ReplicatedStorage.PlayerJoinEvent.OnClientEvent:Connect(function(Playername, PlayerUserId) SendNotification("Join Message", Playername .. "has joined game!", game.players:GetUserThumbnailAsync(PlayerUserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420))

--RealKrautic has joined the game!

end)

2 answers

Log in to vote
0
Answered by 3 years ago

Server Script If your script is a Server script then you can only FireClient(the client here) or FireAllClients() to fire to all players and you you receive OnServerEvent()

Local Script you fireServer() and receive OnClientEvent()

Ad
Log in to vote
0
Answered by 3 years ago

The other answer has a few errors, so im going to fix them

If you fire server, you will recieve OnServerEvent(). You only fire server in a local script and you want to contact with a server script to make a currency change or something like that.

If you fire client, you have to fire the player as well, and the player can be gotten in a bunch of different ways, such as when the player joins, the first parameter of player added is the player. So:

FireClient(playerhere)

then on the client, you would type OnClientEvent()

You can also do FireAllClients, which will fire the event so that all OnClientEvents will run, which is useful if you are making things like guis that will show to everybody.

I hope this has helped you, if so, please accept this answer :)

Answer this question