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

The error: Knife is not a valid member of Model, i dont understand this... can someone help me?

Can someone help me with this error: Knife is not a valid member of Model Knife is a tool inside the Model, WEP at my ReplicatedStorage

So here is the Script:

for i, v in pairs(game.Players:GetPlayers()) do
		backpack = v:FindFirstChild("Backpack")
		if backpack then
			wepaasd = v:FindFirstChild("Weapon") -- check if the player has the StringValue, Weapon
			if wepaasd then
-- error
				if wepaasd.Value == "Knife" then
					tool = weps.Knife
					tool:Clone()
					tool.Parent = backpack
-- could be an error...
				elseif wepaasd.Value == "Sword" then
					tool1 = weps.Sword
					tool1:Clone()
					tool1.Parent = backpack
				end
			end
		end
	end

I made multiple edits and tests, but still, the error is still inside the script. Admins, please lock this question when i approved a helpful answer...

1 answer

Your error means that you tried to access something that didn't exist. In this case, on line 8, then you tried to access the nonexistant child 'Knife' from your variable 'weps'.



To fix this, then you could try checking if the child, and use the FindFirstChild function before actually trying to manipulate it.

Example;

local tool = weps:FindFirstChild('Knife')
if tool then
	--code
end


Another reason why this may not be working is because simply the script has loaded before the actual 'Knife' instance. In this case, use the WaitForChild function.

Example;

local tool = weps:WaitForChild('Knife')
--code

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