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

How do I send the notification?

It never sent any error; it just never showed up. I tried using a Remote Event and the same thing happened. I tried using a Remote Function and it kept saying either these two things: Unable to cast value to object, Missing value or nil.

Local Script

sgui = game:GetService("StarterGui")
wait(5)
game.ReplicatedStorage.Notify.OnClientInvoke:Connect(function(plr,guitext,guititle)
	if plr then
		print("All clients are notified.")
	sgui:SetCore("SendNotification",{Title = guititle, Text = guitext, Icon = "", Duration = 5})
	else
	print("Something went wrong.")
	end
end)

Server Script

game.Players.PlayerAdded:Connect(function(plr)
	local guititle = "A Moderator has entered the server."
	local guitext = plr.Name.." has entered the server."
	game.ReplicatedStorage.Notify:InvokeClient(plr,guititle,guitext)
end)

It never showed where it went wrong, despite looking on the dev wiki or devforum.

2 comments

0

does it "say something went wrong."?

0

No. Not even showing the notification

1 answer

When you Invoke or Fire TO the client, the plr argument gets consumed and used to identify which client. Therefore, that argument is not given to the OnClientInvoked or OnClientEvent function.

So to fix your OnClientInvoked:

...OnClientInvoke:Connect(function(guitext,guititle)

Also, you cannot 'Connect' the OnClientInvoked to a function like that since its not an Event.

Trying writing it like this:

local notifyFunction(guitext,guititle)
	...
end

game.ReplicatedStorage.Notify.OnClientInvoke = notifyFunction

I would suggest just using a RemoteEvent unless you are returning a value.

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