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

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

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

4 comments

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

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.

0

The scripts are separate one is for firing the event and one that connects on server event

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.

1 answer

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)

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