I want to keep checking if my tool, pistol, is in the character. Here's the script I tried to make:
01 | game.Players.PlayerAdded:Connect( function (player) |
02 | local character = player.Character or player.CharacterAdded:Wait() |
03 | while true do |
04 | wait( 1 ) |
05 | for i, v in pairs (character:GetChildren()) do |
06 | if v.Name = = "Pistol" then |
07 | print ( "Pistol found" ) |
08 | end |
09 | end |
10 | end |
11 | end ) |
Tool has two useful events which may be helpful for you, these are Equipped
and Unequipped
Using your example you could detect what tool is equipped through this method:
01 | game.Players.PlayerAdded:Connect( function (Player) |
02 | Player.CharacterAdded:Connect( function (Character) |
03 | for _, Tool in pairs (Player.Backpack:GetChildren()) do |
04 | if Tool:IsA( 'Tool' ) then |
05 | Tool.Equipped:Connect( function () |
06 | print (Tool.Name .. ' has been equipped by ' .. Player.Name) |
07 | end ) |
08 | end |
09 | end |
10 | end ) |
11 | end ) |