Unable to cast value to Object

Hello. I’m getting the error Unable to cast value to Object coming from line 6 of this server script:

local EventFolder = game.ReplicatedStorage.HPRCEvents
local ClickDetector = script.Parent.ClickDetector

ClickDetector.MouseClick:Connect(function(plr)
	local plrName = plr.Name
	EventFolder.KeypadClick:FireClient(plrName)
end)

Heres the local script if that matters

local EventFolder = game.ReplicatedStorage.HPRCEvents
local Players = game:GetService("Players")
local Client = Players.LocalPlayer

EventFolder.KeypadClick.OnClientEvent:Connect(function(plrName)
	if Client.Name == plrName then
		script.Parent.Frame.Visible = true
	end
end)
1 Like

Pass in the palyer instance, not the name

EventFolder.KeypadClick:FireClient(plr)

2 Likes

Yeah I tried that. And it just doesn’t do anything.

Change your OnClinetEvent to this

EventFolder.KeypadClick.OnClientEvent:Connect(function()
	script.Parent.Frame.Visible = true
end)

You don’t need to verify the name of the player given (which is going to be nil in you rcase since the first given arguments starts after you give the player instance is the same as the localPlayer

1 Like

But… I do.

The script is in a ScreenGui parented to StarterGui. So if I did that, then it would show up for everyone. I only want it to be visible to the player who clicked it.

1 Like

It won’t show up for everyone. It’ll only show up for everyone if you used FireAllClients. FireClient only sends the event to the player you requested.

1 Like

It will not, Guis in StarterGui get replicated to everyone’s PlayerGui, if you’re only firing it to one person, it’ll only show up for that person you fired it to

1 Like