ToolBug.rbxl (56.1 KB)
I have two tools in ServerStorage. These two tools have an identical LocalScript inside both of them. With a server script, I am distributing these two tools to the player. One of the tools I am equipping for them, instantly after being parented to their Backpack. The tool that gets equipped runs its local script twice, once when it is created and parented to Backpack, the next time when the tool is equipped. I have verified this using prints in the local scripts. This happens 100% of the time. The local script in the tool should only run once, on creation.
Reproduction steps:
- Create an empty place
- Set SignalBehavior property of Workspace to Default
- Create two tools, both with an identical LocalScript with a print inside it to verify that it is running. Put these tools in ServerStorage.
- Create a script in ServerScriptService that, within a CharacterAdded event, clones these two tools and parents them to the player’s Backpack. Then, equip one of the tools with humanoid:EquipTool() OR by manually parenting it to their character.
- Run a studio test and observe that the output displays 3 prints, rather than the expected 2 prints, as there are only 2 tools being added to your Backpack.
This is what the output looks like if the bug occurs. I am printing the tool and tool.Parent. The tool that was equipped, Tool2, prints twice, and by the second time it runs it is parented to the character (i.e. when it is equipped).
There are multiple ways that stop the bug from happening which causes the expected behaviour (the localscript inside runs only once):
- Include a task.wait() either before creating the tools, or in between creating and equipping.
- Setting the SignalBehavior property of Workspace from Default to Deferred.
- Simply do not equip the tool for the player (letting them equip it manually).