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

"OnServerEvent can only be used on the server" what to do about this error?

Asked by
bnxDJ 57
5 years ago

I am trying to make a server Notify button but I don't know what to do about this error :/

The Notify Remote event is in the replicated storage

this script is in the GUI that recieves the server event (local script)

local Notify = RepStorage:WaitForChild("Notify")
local GameTitle = Minigames:WaitForChild("Game")
local GameDescription = Minigames:WaitForChild("Description")


Notify.OnServerEvent:connect(function()
    GameTitle.Text = ("Title")--Sets notifications game title
    GameDescription.Text = ("game description")--sets notifications description
end)

this script is in the other GUI that fires the event (local script)


local RepStorage = game:WaitForChild("ReplicatedStorage") local Notify = RepStorage:WaitForChild("Notify") local NotifyB = SRMenu:WaitForChild("Notify")-button local Wait = false NotifyB.MouseButton1Click:Connect(function() if Wait == false then Wait = true SRNotify:FireServer() SRNotifyB.Text = ("Notify Players...") wait(1) NotifyB.Text = ("Notify Players") Wait = false end end)

thanks for helping

0
If you want to recieve information from server you need to use OnClientEvent. Shorter if you using LocalScript - type OnClientEvent. If normal script OnServerEvent HaveASip 494 — 5y
1
Do both scripts need to be separate? If they're supposed to affect the same client you can put it all into one local script. xPolarium 1388 — 5y
0
The scripts are separate one is for firing the event and one that connects on server event bnxDJ 57 — 5y
0
For a notify event I would recommend firing a client event from the server. You would use FireClient in a ServerScript and OnClientEvent in a Local Script with your code. TiredMelon 405 — 5y

1 answer

Log in to vote
0
Answered by
Tizzel40 243 Moderation Voter
5 years ago
Edited 5 years ago

The problem is that the mothed OnServerEvent can only be called on the server and not the client (which is that local script you have)

You must Fire the Client on a Script (From the Server)

Since its a "Notification" meaning that you want the local players only and not the server to see it

I recommend to fire the client using the method FireClient and also use the OnClientEvent method too.

Remember :RemoteEvent = Server to Client or Client to Server (when you fire from the client)

Ad

Answer this question