Unable to cast Value to object

So im devloping a game, and there’s like a shop in spawn,
i want it so that when a player touched the Shop part, the Shop Gui is visible.
So i tried to do this in Server Script Service

local ArmorShopPart = game.Workspace.Spawn.ArmorShopPart.ShopGui.ShopPart
ArmorShopPart.Touched:Connect(function(Plr)
	if Plr.Parent:FindFirstChild("Humanoid") then
		game.ReplicatedStorage.OpenArmorShopEvent:FireClient(Plr.Name)
	end
end)

and this in Starter Player Scripts

local Event = game.ReplicatedStorage.OpenArmorShopEvent

Event.OnClientEvent:Connect(function(Player)
	if game.Players.LocalPlayer.Name == Player then
		game.PlayerGui.ArmorShopGui.MainFrame.Visible = true
		game.PlayerGui.ArmorShopGui.BgFrame.Visible = true
	end
end)

But it gave me this error
“Unable to Cast Value to Object”
and the line the error showed me was

game.ReplicatedStorage.OpenArmorShopEvent:FireClient(Plr.Name)

Ima a begginer in Lua and I dont know that well of english so
Pls explain/help me in simple english

Thanks For Reading,
The Spikey Man

local ArmorShopPart = game.Workspace.Spawn.ArmorShopPart.ShopGui.ShopPart
ArmorShopPart.Touched:Connect(function(Plr)
	if Plr.Parent:FindFirstChild("Humanoid") then
		game.ReplicatedStorage.OpenArmorShopEvent:FireClient(Plr)
	end
end)

Pass in the player instance not the name of the player.

For clarity change this code:

game.ReplicatedStorage.OpenArmorShopEvent:FireClient(Plr.Name)

Into this:

game.ReplicatedStorage.OpenArmorShopEvent:FireClient(Plr)

sorry, im back, was eating food.
see if did this

local ArmorShopPart = game.Workspace.Spawn.ArmorShopPart.ShopGui.ShopPart
ArmorShopPart.Touched:Connect(function(Plr)
	if Plr.Parent:FindFirstChild("Humanoid") then
		game.ReplicatedStorage.OpenArmorShopEvent:FireClient(Plr)
	end
end)

then this script would be like this?

local Event = game.ReplicatedStorage.OpenArmorShopEvent

Event.OnClientEvent:Connect(function(Player)
	if game.Players.LocalPlayer == Player then
		game.PlayerGui.ArmorShopGui.MainFrame.Visible = true
		game.PlayerGui.ArmorShopGui.BgFrame.Visible = true
	end
end)

or like this?

local Event = game.ReplicatedStorage.OpenArmorShopEvent

Event.OnClientEvent:Connect(function(Player)
	if game.Players.LocalPlayer.Name == Player then
		game.PlayerGui.ArmorShopGui.MainFrame.Visible = true
		game.PlayerGui.ArmorShopGui.BgFrame.Visible = true
	end
end)

So i tested this out

local ArmorShopPart = game.Workspace.Spawn.ArmorShopPart.ShopGui.ShopPart
ArmorShopPart.Touched:Connect(function(Plr)
	if Plr.Parent:FindFirstChild("Humanoid") then
		game.ReplicatedStorage.OpenArmorShopEvent:FireClient(Plr)
	end
end)
local Event = game.ReplicatedStorage.OpenArmorShopEvent

Event.OnClientEvent:Connect(function(Player)
	if game.Players.LocalPlayer == Player then
		game.PlayerGui.ArmorShopGui.MainFrame.Visible = true
		game.PlayerGui.ArmorShopGui.BgFrame.Visible = true
	end
end)

but it says this
" FireClient: player argument must be a Player object "
pls help @Mystxry12

i think what you need to do is

local ArmorShopPart = game.Workspace.Spawn.ArmorShopPart.ShopGui.ShopPart
ArmorShopPart.Touched:Connect(function(TouchedPart)
	if TouchedPart.Parent:FindFirstChild("Humanoid") then
        local Character = TouchedPart.Parent
        local plr = game.Players[Character.Name]
        game.ReplicatedStorage.OpenArmorShopEvent:FireClient(plr)
	end
end)

Also you don’t need the “if game.Players.LocalPlayer == Player then” so just put

local Event = game.ReplicatedStorage.OpenArmorShopEvent

Event.OnClientEvent:Connect(function(Player)
	game.PlayerGui.ArmorShopGui.MainFrame.Visible = true
	game.PlayerGui.ArmorShopGui.BgFrame.Visible = true
end)

You can add an if statement to see if the MainFrame is visible or not though, or even a debounce so the player isn’t constantly spammed by the Frame whenever they move on the shop part

game.ReplicatedStorage.OpenArmorShopEvent:FireClient(Plr)

@paetemc2 can u pls help me with the debounce thing and whether the main frame is visble, idk how to do that

something like this could do it (it’s not perfect, but it will do the job)

local Event = game.ReplicatedStorage.OpenArmorShopEvent

local db = false

Event.OnClientEvent:Connect(function(Player)
    if db or game.PlayerGui.ArmorShopGui.MainFrame.Visible then return end
    db = true
	game.PlayerGui.ArmorShopGui.MainFrame.Visible = true
	game.PlayerGui.ArmorShopGui.BgFrame.Visible = true
    repeat task.wait() until game.PlayerGui.ArmorShopGui.MainFrame.Visible == false
    task.wait(1)
    db = false
end)

Ayyy, I figured it Out, @paetemc2 ur code didnt work, here is the code which worked for me
ServerScriptService :-

local ArmorShopPart = game.Workspace.Spawn.ArmorShopPart.ShopGui.ShopPart
ArmorShopPart.Touched:Connect(function(TouchedPart)
	if TouchedPart.Parent:FindFirstChild("Humanoid") then
		local Character = TouchedPart.Parent
		local plr = game.Players[Character.Name]
		game.ReplicatedStorage.OpenArmorShopEvent:FireClient(plr)
	end
end)

and in the Starter Player Scripts :-

local Event = game.ReplicatedStorage.OpenArmorShopEvent

local db = false

Event.OnClientEvent:Connect(function(Player)
	local Plr = script.Parent.Parent
	if db or Plr.PlayerGui.ArmorShopGui.MainFrame.Visible then return end
	db = true
	Plr.PlayerGui.ArmorShopGui.MainFrame.Visible = true
	Plr.PlayerGui.ArmorShopGui.BgFrame.Visible = true
	repeat task.wait() until Plr.PlayerGui.ArmorShopGui.MainFrame.Visible == false and Plr.PlayerGui.ArmorShopGui.BgFrame.Visible == false
	task.wait(1)
	db = false
end)

everyone Thanks for the Help :slight_smile: