Changing the way of locating what was supposed to be multiple instances only works for one instance!

Help, I need someone to help me in this script, And yes, It’s something with FE Gun Kit again.
In the original FE Gun Kit, The thing that makes the tool works is a local script inside the tool, I am trying to make that one
local script makes every gun in game works without it being inside the tool
How? I move the local script to startercharacter script and makes the script locates every tool with getdescendants and the rest of the script will handle how the gun works. It’s perfectly fine when i test it ONLY with 1 tool, But when i tests it with 2 tools, Only one of them works. And that means it’s not able to make every tool ingame works, which is my goal.

Provide an overview of:

*** What does the code do and what are you not satisfied with?**
local Player = game:GetService(“Players”).LocalPlayer

local children = Player.Backpack:GetDescendants()

for index, descendant in pairs(children) do

if descendant:IsA(“Tool”) then

Tool = descendant

end

end
(then the rest of the script provides function connected to the tool, example: equipping does this, etc.)

The script that locates the tool works perfectly fine, But it only locates one tool and i can’t make it work for every tool ingame.
*** What potential improvements have you considered?**
At first, I was using GetChildren then i replaced it with GetDescendant, Nothing changes unfortunately.
** * How (specifically) do you want to improve the code?**
I want to make the code works for every tool ingame and not only 1.

Thank you for anyone that will help, I will try to find a solution whilst waiting for an answer.

I think tools only work in Local Scripts, since they are part of the Player’s Backpack.
If they were a Server Script the player would probably get some lag while their device communicated with the Server and then it communicated back.

I did not genuinely change anything inside the script
other than changing the way the script locates the tool from locating only 1 tool into locating
every tools ingame or in the backpacks using GetDescendants, But it was not working.

Did you read this: In-Experience Tools | Roblox Creator Documentation
It mentions the different Local and Server script uses in tools.

You definitely get it the wrong way, I am not trying to
do anything inside the script that makes the gun working.
You should read again. It’s about trying to locate the tools, Not trying to give them new functions or something.

You are setting the Tool variable to descendant but the thing is that the script runs only once so whatever Tool is set to last, that will be the working one.

One way to fix this would be to put the rest of the script in the same loop as you are setting Tool, another thing you could try would be to use CollectionService which is great for having one script that manages a group of tags (which you will learn about if you look more into CollectionService).

Thank you for your help, but i’m not sure how to do it because i’m new to this Collection Service stuff. Can you show me
like how you would change the script i am provided in locating the tools using Collection Service like
you mentioned? Thank you so much. It’s fine if you don’t

I personally have never used CollectionService but looking at the documentation you should just be able to use the code examples I provide, in your use case.

local Player = game:GetService("Players").LocalPlayer
local Tools = Player.Backpack:GetChildren() -- You can change this to GetDescendants() if you need.
local CollectionService = game:GetService("CollectionService")
local TagName = "ToolTag" -- You can change the name, it does not need Tag in it either.

for i, v in pairs(Tools) do
    if descendant:IsA("Tool") then
          CollectionService:AddTag(v, TagName)
    end
end

for _, v in pairs(CollectionService:GetTagged(TagName)) do
	-- Put the script that shoots (I assume it is a RemoteEvent but I am not sure since you did not supply the full script).
end
1 Like

Thank you so much, You have really helped me in this problem.
I hope you have a great day and again, thank you so much!

Your welcome, if you have any more problems don’t feel afraid to ask for more help.

1 Like