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

Error: invalid argument #3 (string expected, got nil)?

I get this error: invalid argument #3 (string expected, got nil). These are the scripts:

Server script:

local rigs = game.Workspace.Rigs:GetChildren()
local event = game.ReplicatedStorage.RigTouched

for _, rig in pairs(rigs) do
	rig.OpenGuiPart.ClickDetector.MouseClick:Connect(function(player)
		local rigID = rig.ClothingID.Value
		event:FireClient(player, rigID)
	end)
end

Local script:

local event = game.ReplicatedStorage.RigTouched
local CurrentClothingID = script.Parent.ShopBackround.CurrentClothing

event.OnClientEvent:Connect(function(player, rigId)
	script.Parent.ShopBackround.Visible = true
	CurrentClothingID.Value = rigId
	print(rigId)
end)

I have read the code several times but still do not understand what is the problem. The error is on line 6 of the local script.

2 comments

0

Try removing the "player" inside the parameters (Script) because when your firing those event roblox already knows the player so you dont need to put it

0

To the person above me, this is incorrect. OnClientEvent has no player argument. Only OnServerEvent has this.

1 answer

I see the mistake. You see, only OnServerEvent needs the player argument. OnClientEvent doesn't. So on the local script, do this instead:

local event = game.ReplicatedStorage.RigTouched
local CurrentClothingID = script.Parent.ShopBackround.CurrentClothing

event.OnClientEvent:Connect(function(rigID)
	script.Parent.ShopBackround.Visible = true
	CurrentClothingID.Value = rigId
	print(""..rigID)
end)

1 comment

0

also, in the server script, you gave the parameter rigID, so on the local script you have to do rigID too instead of rigId

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