Invalid argument #2 (string expected, got Instance) error

No idea why this error is outputting as I have tried several different methods and read up about 5-6 different community posts with answers that work so no clue on my part.

However I would greatly appreciate any sort of help, This script locates toolcamera which is a camera and the shops name, but on the part where it’s supposed to have the name of the shop it outputs in an error, So if anyone would know why I would greatly appreciate the help.

Shop + Descendants :
image

Main script in shop :

local proximityprompt = script.Parent
local event = game.ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("NewShop")

proximityprompt.Triggered:Connect(function(plr)
	local shop = script.Parent.Parent.Parent.HotDogStandSans.Name
	local toolCamera = script.Parent.Parent.Parent:FindFirstChild("Camera")
	event:FireClient(plr,toolCamera,shop)
end)

Local script which handles the shop :

if not game.Players.LocalPlayer.Character then game.Players.LocalPlayer.CharacterAdded:Wait() end

local firstevent = game.ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("NewShop")
local currentCam = workspace.CurrentCamera
local tweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ShopFolder = ReplicatedStorage:WaitForChild("Shops")

function Invisible(TurnsInvisible)
	if TurnsInvisible == true then
		for i,v in pairs(game.Players.LocalPlayer.Character:GetDescendants()) do
			if v:IsA("MeshPart") or v:IsA("Part") or v:IsA("Decal") then
				if v ~= game.Players.LocalPlayer.Character.PrimaryPart then
					v.Transparency = 1
				end
			elseif v:IsA("Accessory") then
					v:FindFirstChildOfClass("MeshPart").Transparency = 1
			end
		end
	else
		for i,v in pairs(game.Players.LocalPlayer.Character:GetDescendants()) do
			if v:IsA("MeshPart") or v:IsA("Part") or v:IsA("Decal") then
				if v ~= game.Players.LocalPlayer.Character.PrimaryPart then
					v.Transparency = 0
				end
			elseif v:IsA("Accessory") then
					v:FindFirstChildOfClass("MeshPart").Transparency = 0
			end
		end
	end
end

firstevent.OnClientEvent:Connect(function(shop,toolCamera,plr)
	local ShopGui = ShopFolder[shop].Shop
	local proximityprompt = toolCamera.Parent.ProximityPromptHolder:FindFirstChild("ProximityPrompt")
	proximityprompt.Enabled = false
	currentCam.CameraType = Enum.CameraType.Scriptable
	task.spawn(Invisible,true)
	local camSwitch = tweenService:Create(currentCam, TweenInfo.new(1.75), {CFrame = toolCamera.CFrame})
	camSwitch:Play()
	if not game.Players.LocalPlayer.PlayerGui:FindFirstChild("Shop") then
	local gui = ShopGui:Clone()
	gui.Parent = script.Parent.Parent
	end
end)

Error outputs on line 34 :

	local ShopGui = ShopFolder[shop].Shop

ReplicatedStorage where the shop folder is stored :
image

And again help would be greatly appreciated thank you!

I think when your receiving the client event in the local script the argument order should be plr

1 Like

I mean, correct me if I’m wrong, but you send the remote with the arguments in the following order:

  1. plr (ignored)
  2. toolCamera (Instance)
  3. shop (String)

You receive them (on the client side) in the following order:

  1. shop (will be equal to toolCamera - Instance)
  2. toolCamera (will be equal to shop - String)
  3. plr (will be nil since you never send a 3rd argument)

So you basically got to reverse the arguments from the .OnClientEvent event function.

You should do something like:

firstevent.OnClientEvent:Connect(function(toolCamera, shop)
1 Like

Oh wow it works thank you! : D

1 Like