Can't detect for tool

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)

I would look into AncestryChanged. As you can put it straight into your gun logic.

1 Like

well im trying to make a singular server script that controls any server side operations for guns, and only a local script in the gun

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

try doing player.characteradded and then putting child added in that

Tried it and nothing was output either

can u show ur script now how it looks like

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.

1 Like

okay so thats annoying but solved thanks

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.