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

How do I send the notification?

Asked by 4 years ago

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.

0
does it "say something went wrong."? DollorLua 235 — 4y
0
No. Not even showing the notification marltonjohnson9876 11 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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.

Ad

Answer this question