So im trying to make it where if a player already has a tool in starter gear the npc will say that you already have a weapon, but on line 9 the error says argument 1 missing or nil what am I supposed to do?
cd.MouseClick:Connect(function(plr) if plr.weapon.Value == "Wood Sword"then plr.PlayerGui.itemStatus.Text.name.Text = "Sword gal" plr.PlayerGui.itemStatus.Text.Text = "You already have this!" plr.PlayerGui.itemStatus.Text.Visible = true wait(1.7) plr.PlayerGui.itemStatus.Text.Visible = false else if plr.StarterGear:FindFirstChildOfClass():IsA("Tool") then plr.PlayerGui.itemStatus.Text.name.Text = "Sword gal" plr.PlayerGui.itemStatus.Text.Text = "You already have a weapon, if you want to reset it click on your current weapon GUI." plr.PlayerGui.itemStatus.Text.Visible = true wait(6) plr.PlayerGui.itemStatus.Text.Visible = false
I see multiple problems with this.
Btw I recommend not naming the NPC "Sword gal". You can keep the name if you want.
cd.MouseClick:Connect(function(plr) if plr.weapon.Value == "Wood Sword"then plr.PlayerGui.itemStatus.Text.name.Text = "Sword gal" plr.PlayerGui.itemStatus.Text.Text = "You already have this!" plr.PlayerGui.itemStatus.Text.Visible = true wait(1.7) plr.PlayerGui.itemStatus.Text.Visible = false else if plr.StarterGear:FindFirstChildOfClass("Tool") then --:IsA("Tool") isnt required and you forgot to put ("Tool") in :FirstChildOfClass() plr.PlayerGui.itemStatus.Text.name.Text = "Sword gal" plr.PlayerGui.itemStatus.Text.Text = "You already have a weapon, if you want to reset it click on your current weapon GUI." plr.PlayerGui.itemStatus.Text.Visible = true wait(6) plr.PlayerGui.itemStatus.Text.Visible = false end
[For the complete and correct answer, see CandyWreckEpicness' answer below this one.] [This answer is wrong, and I stand corrected. See comments under this post]
You are just finding if the first child of StarterGear is a tool. Since some players might not have any Tool, Line 9 will give you '1 missing or nil', since you are asking if "nothing" is a tool.
What happens is:
To fix this, you should check first if a child exist.
-Is there a child?/Is it not NIL?
*There is a child.
*There is no child.
if plr.StarterGear:FindFirstChildOfClass() then if plr.StarterGear:FindFirstChildOfClass():IsA("Tool") then plr.PlayerGui.itemStatus.Text.name.Text = "Sword gal" plr.PlayerGui.itemStatus.Text.Text = "You already have a weapon, if you want to reset it click on your current weapon GUI." plr.PlayerGui.itemStatus.Text.Visible = true wait(6) plr.PlayerGui.itemStatus.Text.Visible = false end end
If Line 1 does not work, try
if plr.StarterGear:FindFirstChildOfClass() ~= nil then
But in my experience, "if yes" works the same way as "if not nil"