Unfortunately, it didn’t work.
I am trying to avoid this event, as the script would possibly run way after the tool was equipped.
Which part didn’t work? And did you properly define char
The Backpack would be where the child was added, and I just noticed it was an event, which as I stated, could possibly fire way before the script is used.
You can avoid that by using a bool and checking after the tool is equipped.
If you want to check which tool is equipped, you would look inside the player’s character as that’s where equipped tools are stored. I don’t know what you mean by
So you’re suggesting I should sacrifice performance, and add a script, and a bool value to every tool, (possibly hundreds), just to check if a tool is equipped? I feel like there’s a better solution.
You could also just make the event when it’s needed, or disconnect it until needed
So my mistake, it did work, however, now it names ANY new child that’s added “Cup w/ Ice”. How would I combat that? Script:
local function onTriggered(Player)
if Player and Player.Character then
local Backpack = Player:WaitForChild("Backpack")
if Backpack:FindFirstChild("Cup") then
local Cup = Backpack:FindFirstChild("Cup")
local equippedTool
Player.Character.ChildAdded:Connect(function(child)
if child:IsA("Tool") then
equippedTool = child
equippedTool.Name = "Cup w/ Ice"
end
end)
end
end
end
script.Parent.Triggered:Connect(function(Player)
onTriggered(Player)
end)
Tool.Equipped and a bool wouldn’t affect performance all that much actually. Especially doing it client side. I don’t know what information you’ve been reading, but unless your game has hundreds of tools it wouldn’t hurt your performance. 100’s of Tools meaning you physically have hundreds of tools not that every player accounts for 100 or more tools. Tool.Equipped is ran client side anyways there wouldn’t be performance issues server side.
There are also 26 more machines I have to add this script to, I could try your solution, but it feels like a few extra un-needed steps.
If you don’t want it in an event, you could also use
equippedTool = character:FindFirstChildWhichIsA("Tool")
But with it naming everything “Cup w/ Ice” I don’t know why it would do that, as the script checks to make sure that a Tool is added
So the other machines name the cup totally different names, not just “Cup w/ Ice”, and I will try the one without the event right now!
local char = Player.Character
local equippedTool = char and char:FindFirstChildWhichIsA("Tool")
if equippedTool then
print(equippedTool)
else
print("No tool equipped!")
end
Do you have any idea where equipped tools get stored? Is there a specific location?
They get parented to the plrs character. Nothing fancy. (lik a folder named ‘Tool’)
When a tool is equipped it’s parented inside the player character, then when they unequip the tool it gets parented inside their backpack.
I’ll figure out a way to do it, thanks for the help.
Ok my bad I just actually read the post, mb youre doing this server side. I was completely wrong. Tool.Equipped would be bad xd. I was going from the perspective of the client. The tools when equipped are in the character model inside the workspace. When not equipped they are inside the players backpack > which can be retrieved via game.Players.PlrName.Backpack. Me personally would have a module and have all my tools inside a table. Then reference it when something would enter the character using childadded > IsA:(‘Tool’) to check if its actually what I’m looking for. Then inside the table of the module id remove the tool from the table and just add it back when the tool comes back to the backback > using childadded, IsA(tool) > Of course you could attempt to try using attributes over table values.
Ah, thank you. I might try this if I can’t figure it out!