Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 9 years ago

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

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

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
Ad

Answer this question