Let's say I want to make a tool when you equip it the name of the tool is the AccountAge of the player. (I don't want to script that its just an example) how would I get to the correct player?
I did this:
tool.Activated:Connect(function() Tool = script.Parent PLAYERNAME = Tool.Parent.Name PLAYER = game.Players:FindFirstChild(PLAYERNAME) Tool.Name = PLAYER.AccountAge end)
but in output a message appeared:
Players.TechGamar.Backpack.Taser.Script:5: attempt to index global 'Tool' (a nil value)
so how do I get to the player?
Please help me.
Ok, so first, you may wanna fix your syntax, second, your problem is that when you're saying Tool.Parent.Name
, your refering to Backpack, cuz the parent of the tool is backpack, and backpack is parented to your player, now fixing that should be easy. And btw, one of the biggest issues in your script is tahtyoure using global variables, its recommended to alwyas use local vars, and if they are local you always wanna put them outside of your function, or exaclty your scope, (scope is the content inside your function).
im not sure if you did this or not, but in order for this to work, a part named "Handle" should be parented to your tool.
now this should be your script:
local tool = script.Parent local plrname = tool.Parent.Parent.Name local plr = game:GetService("Players"):FindFirstChild(plrname) tool.Equipped:Connect(function() tool.Name = plr.AccountAge end)
(this was tested and it worked) so, if i explain again, we made all vars local and outside of the function, always do that, and we fixed the plr.Name, always expiremnt stuff, see if an obj is parented to another, see if somethin is duable... always fo this stuff https://gyazo.com/cc754edbb2665956c1a7f9c260854ddd
happy to help!