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

How to check somethings parent?

Asked by 9 years ago

Here is my code, I cant figure it out.

if Hammer.Handle = game.LocalBackpack

end

Thanks.

1 answer

Log in to vote
0
Answered by 9 years ago

You coded it wrong, lets fix that [Would do inside tool];

repeat wait() until game.Players.LocalPlayer and game.Players.LocalPlayer:FindFirstChild("Backpack") and script.Parent --I like to use this so that the script will repeat waiting until the requiements are found; this will repeat waiting until the Player, Player's Backpack, and Tool spawns
local plr = game.Players.LocalPlayer --This is the Player
local backpack = plr.Backpack --This is the Player's Backpack

if script.Parent.Parent == backpack then --This will check to see if the Tool's Parent is in the Player's Backpack [You forgot the 'then', and didn't include '.Parent', so it couldn't check the Parent]
print('I\'m in '..plr.Name..'\'s Backpack!') --It will print 'I'm in [Player's Name]'s Backpack!'
end --This ends the code for the 'if' statement

script means the script [Represents the Script], script.Parent means the script's Parent [Represents the Script's Parent], .Parent represents the Parent for an object. Hope this helped!

Ad

Answer this question