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

Finding a variable that's a child?

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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
0
Oh ok thanks that worked UNBANhappyniceguy5 52 — 5y
0
Can you label this as the right answer then please. funface101 45 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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

player.Character.Humanoid:EquipTool(gun)

Answer this question