Hi, I'm making a script that detects if a character is using a tool, and if it does, save the tool at a Value. I made this, but It seems like it doesn't work....
local children = plr.Character:GetChildren() for i = 1, #children do if children[i].ClassName == "Tool" then local tool = children[i] end end
It's inside a script and plr is a Player inside Players.
Could someone explain what am I doing wrong? Or if there is another more efficient way to get the tool a character is using, please tell me!
You're using a local variable for tool, so it can only be used inside the if statement.
Read this wiki article about local variables
local tool for i,v in pairs(plr.Character:GetChildren()) do if v:IsA("Tool") then tool = v end end print(tool)