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

Finding a variable that's a child?

So I made a simpler post earlier but I guess it didn't answer my question, so I have this script that equips a weapon when you spawn, but the problem is it tries to find something called gun in the backpack but I want it to find the variable that's called gun


local gun = script.Parent.Parent.Backpack:FindFirstChild(script.Value.Value) -- gun
local plr = script.Parent.Parent
local plrname = plr.Name


wait(1)
print(gun) -- to verify it works
local player = game.Workspace:FindFirstChild(plrname)
if player then
	if gun then
		player.Humanoid:EquipTool(plr.Backpack.gun) -- ERROR IS HERE
	end
end


2 answers

✓ Accepted answer

Try removing the plr.Backpack, if your not trying to find something in the backpack, why are you looking in the backpack?

local gun = script.Parent.Parent.Backpack:FindFirstChild(script.Value.Value) -- gun
local plr = script.Parent.Parent
local plrname = plr.Name


wait(1)
print(gun) -- to verify it works
local player = game.Workspace:FindFirstChild(plrname)
if player then
    if gun then
        player.Humanoid:EquipTool(gun) -- ERROR IS HERE
    end
end

2 comments

0

Oh ok thanks that worked

0

Can you label this as the right answer then please.

###Line 11. The Player object doesn’t have a Humanoid, but the Character Model does.

player.Character.Humanoid:EquipTool(gun)

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