The title is pretty self explanitory, but I can’t detect if a tool is added, and nothing is in the output. I want it to print when the player is added and when a tool with the tag “Gun” is equipped
wait(0.1)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local FastCast = require(ReplicatedStorage.FastCastRedux)
game.Players.PlayerAdded:Connect(function(Player)
print("added")
Player.Character.ChildAdded:Connect(function(Child)
if Child:IsA("Tool") and Child:HasTag("Gun") then
print("Gun equipped")
end
end)
end)
From what I can see, your using CollectionService, you can just connect the AncestryChanged function when looping through the tools.
Example:
local CollectionService = game:GetService("CollectionService")
local Tags = CollectionService:GetTagged("Gun")
for _, parent in pairs(Tags) do
parent.AncestryChanged:Connect(function()
print("The gun changed parents, new parent: "..parent.Parent.Name)
end)
end
or
local CollectionService = game:GetService("CollectionService")
local Tags = CollectionService:GetTagged("Gun")
for _, parent in pairs(Tags) do
parent.AncestryChanged:Connect(function()
local str = string.format("%s has changed parents, new parent is: %s.", parent.Name, parent.Parent.Name)
print(str)
end)
end
I’d also like to note that even the Print("Player added") Prints, but does if i remove the child added
wait(0.1)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local FastCast = require(ReplicatedStorage.FastCastRedux)
game.Players.PlayerAdded:Connect(function(Player)
print("Player added")
Player.CharacterAdded:Connect(function(Char)
Char.ChildAdded:Connect(function(Child)
if Child:IsA("Tool") then
print("Tool equipped")
end
end)
end)
end)
It’s not printing anything because you added wait(0.1) at the start of the script. When you join the game, the script only detects players who are added after the 0.1-second delay, so it doesn’t print anything.