Scripting tool from the outside

I’ve tested this and it should work. I’ve placed my Tool inside of StarterPack and the local script is inside of StarterCharacterScripts in StarterPlayer.

The code is:

local Tool = game:GetService("Players").LocalPlayer.Backpack:WaitForChild("Tool")

if Tool then

print(Tool.Name)

end

Explanation:

In the first line I am trying to find a Player’s backpack and I will wait for the Tool inside of it when player spawns.

After that I will check if that Tool exists, if it does then print the name.

Hope this helps! :slight_smile:

2 Likes

Because if you don’t have the tool equipped, it doesn’t make sense that you can do anything with it, so when the player equips himself an object, he is in the character, which is what I understand he needs.

This works. Thank you.
I also added a WaitForChild for the Backpack. I find it really weird that the script doesn’t work when put inside of StarterPlayerScripts, but I will use StarterCharacterScripts.

1 Like

I will explain a bit more, so everybody else can understand this without getting confused.

Class is a blueprint in Object-Oriented Programming, which can allow you to create objects.
They are really useful in programming and it’s used very often.

StarterCharacterScripts is a class which stores all your scripts inside of Player’s Character, which is actually the model of your Player in the workspace when you join the game.
image
Inside your Player’s Character you can find elements that makes your Character.

Those elements are: Humanoid, HumanoidRootPart, All of the BodyParts etc.

StarterPlayerScripts is also a class, which stores all your scripts inside of the PlayerScripts, which are located here:

image

As far as I have understood, this is what Developer Hub said about PlayerScripts.

Unlike the Backpack and PlayerGui containers, the PlayerScripts container is not accessible to the server. Server Script objects will not run when parented to PlayerScripts .

I believe this means that any local script from inside the StarterPlayerScripts can’t interact with Backpack or PlayerGui.

Now I hope you understand why does it not work, if you place the script inside of StarterPlayerScripts.

I will leave few links to read more about this, which can help you in the future scripting!

https://developer.roblox.com/en-us/api-reference/class/StarterPlayer
https://developer.roblox.com/en-us/api-reference/class/StarterPlayerScripts
https://developer.roblox.com/en-us/api-reference/class/StarterCharacterScripts
https://developer.roblox.com/en-us/api-reference/class/PlayerScripts

Thanks for reading! :grin:

2 Likes