Character:FindFirstChild(Tool) Doesn't work

  1. What do you want to achieve? Keep it simple and clear!
    I want to fix the problem with my script.

  2. What is the issue? Include screenshots / videos if possible!
    The issue is that I don’t know how to fix it because it is happening for the first time to me.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried but I couldn’t find any solutions.

Script: (Local Script)

--// Services
local Lightning = game:GetService("Lighting")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local StarterGui = game:GetService("StarterGui")

--// Player
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChild("Humanoid")

--// Tool
local Tool = script.Parent

--// Folders
local ModulesFolder = ReplicatedStorage.ATPS.Modules
local AnimationsFolder = ReplicatedStorage.ATPS.ToolAnim
local RemoteEventsFolder = ReplicatedStorage.ATPS.RemoteEvents

--// Remote Events
local ATPSCredit = RemoteEventsFolder["ATPS | Credit"]

--// Modules
local GlobalConfig = require(ReplicatedStorage.ATPS.GlobalConfig.Config)
local Camera = require(ReplicatedStorage.ATPS.Modules.Camera)

--// Variables
local CanFire = true
local CanAim = false
local ChangeShoulderDB = false

--// Equip
Character.ChildAdded:Connect(function(Obj)
    if Obj == Tool then
        Camera:Enable()
        Camera:SetCharacterAlignment(true)
    end
end)

--// UnEquip
Character.ChildRemoved:Connect(function(Obj)
    if Obj == Tool then
        Camera:SetCharacterAlignment(false)
        Camera:Disable()
    end
end)

UserInputService.InputBegan:Connect(function(input, gameProccessed)
    if input.KeyCode == Enum.KeyCode.T and Character:FindFirstChild(Tool) then
        if ChangeShoulderDB == false then
            Camera:SetShoulderDirection(-1)
            ChangeShoulderDB = true
        elseif ChangeShoulderDB == true then
            Camera:SetShoulderDirection(1)
            ChangeShoulderDB = false
        end
    end
end)

Character.ChildRemoved:Connect(function(Obj)
    if Obj:IsA("LocalScript") and Obj.Name == "Client" then
        Player:Kick("Client detected suspicious changes.")
    elseif Obj:IsA("LocalScript") and Obj.Name == "AntiExploit" then
        Player:Kick("Client detected suspicious changes.")
    end
end)

if input.KeyCode == Enum.KeyCode.T and Character:FindFirstChild(Tool) then
Is a OBJ, not a string. obj:FindFirstChild() from what I know, it only uses strings/names to find items.

This snippet, should fix your issue.

--// Services
local Lightning = game:GetService("Lighting")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local StarterGui = game:GetService("StarterGui")

--// Player
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChild("Humanoid")

--// Tool
local Tool = script.Parent

--// Folders
local ModulesFolder = ReplicatedStorage.ATPS.Modules
local AnimationsFolder = ReplicatedStorage.ATPS.ToolAnim
local RemoteEventsFolder = ReplicatedStorage.ATPS.RemoteEvents

--// Remote Events
local ATPSCredit = RemoteEventsFolder["ATPS | Credit"]

--// Modules
local GlobalConfig = require(ReplicatedStorage.ATPS.GlobalConfig.Config)
local Camera = require(ReplicatedStorage.ATPS.Modules.Camera)

--// Variables
local CanFire = true
local CanAim = false
local ChangeShoulderDB = false

--// Equip
Character.ChildAdded:Connect(function(Obj)
    if Obj == Tool then
        Camera:Enable()
        Camera:SetCharacterAlignment(true)
    end
end)

--// UnEquip
Character.ChildRemoved:Connect(function(Obj)
    if Obj == Tool then
        Camera:SetCharacterAlignment(false)
        Camera:Disable()
    end
end)

UserInputService.InputBegan:Connect(function(input, gameProccessed)
    if input.KeyCode == Enum.KeyCode.T and Character:FindFirstChild(Tool.Name) then
        if ChangeShoulderDB == false then
            Camera:SetShoulderDirection(-1)
            ChangeShoulderDB = true
        elseif ChangeShoulderDB == true then
            Camera:SetShoulderDirection(1)
            ChangeShoulderDB = false
        end
    end
end)

Character.ChildRemoved:Connect(function(Obj)
    if Obj:IsA("LocalScript") and Obj.Name == "Client" then
        Player:Kick("Client detected suspicious changes.")
    elseif Obj:IsA("LocalScript") and Obj.Name == "AntiExploit" then
        Player:Kick("Client detected suspicious changes.")
    end
end)
1 Like

no, FindFirstChild() can be used for objects too.

Try doing Tool.Name instead of just Tool.

No it can’t, FindFirstChild requires a string argument and an optional Boolean argument.
https://developer.roblox.com/en-us/api-reference/function/Instance/FindFirstChild
Object:FindFirstChild("Name", true) --Second argument defaults to 'false'.