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

Unable to cast value to Object?

I'm trying to test of making a notification. I kept getting this error (Unable to cast value to Object). The error is on Line 5 of the server script.

Use both scripts if needed:

--]]//SERVER SCRIPT\\[[--

local RS = game:GetService("ReplicatedStorage")
local noti = RS.RemoteEvents:WaitForChild("Notify")

game.Players.PlayerAdded:Connect(function()
	noti:FireClient("Test", "Hello.")
end)
--]]//LOCAL SCRIPT\\[[--

local RS = game:GetService("ReplicatedStorage")
local noti = RS.RemoteEvents:WaitForChild("Notify")
local SG = game:GetService("StarterGui")


noti.OnClientEvent:Connect(function(Title, Text)
	SG:SetCore("SendNotification", {
		Title = Title;
		Text = Text;
		
	})
end)

1 answer

✓ Accepted answer

When you use FireClient(), the first parameter always has to be the player your targeting.

--]]//SERVER SCRIPT\\[[--

local RS = game:GetService("ReplicatedStorage")
local noti = RS.RemoteEvents:WaitForChild("Notify")

game.Players.PlayerAdded:Connect(function(newPlayer) -- PlayerAdded event automatically sets the first parameter to the player who joined
    noti:FireClient(newPlayer, "Test", "Hello.")
end)

1 comment

0

Thanks :D

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