Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I detect a tool in a character?

Asked by 5 years ago
Edited 5 years ago

So simply put I want this script to detect which weight is in the back pack. If its W0 I want to give 10 points and W1 gives 20 points and so on. The first weight works and adds the value of 10 to the strength leaderboard. But for some reason this script cant find W1 in the character. The weight that I can detect is W0 which is placed in the starterpack for first time players.

Notes: - W0 through W4 is the name of each of the weights names. These are the tool holder. These 4 tools are in lighting - Cloning process to character works.

Question: Why cant this script find tools W1 through W4 in the character even though they are successfully cloned and I can see that they are in the character.

The purpose of this is to figure out which weight it is to add the different strength values to leader board. So if I have weight W1 I want it to add 20 but I cant add it if I dont know which one the player has.

01local replicatedStorage = game:GetService("ReplicatedStorage")
02local remoteData = game:GetService("ServerStorage"):WaitForChild("RemoteData")
03local starterRebirthAmount = 100
04local coolDown = 1
05 
06replicatedStorage.Remotes.Lift.OnServerEvent:Connect(function(player)
07    if not remoteData:FindFirstChild(player.Name) then return "NoFolder" end
08 
09    local debounce = remoteData[player.Name].Debounce
10 
11    if not debounce.Value then
12        debounce.Value = true
13            local Animation = Instance.new("Animation")
14        --Animation.AnimationId = "http://www.roblox.com/asset/?id=507771019"
15        Animation.AnimationId = "rbxassetid://4479273224"
View all 53 lines...

3 answers

Log in to vote
0
Answered by
NSMascot 113
5 years ago

maybe do :GetDescendants() --Google It...

Ad
Log in to vote
0
Answered by 5 years ago
01local Players = game:GetService("Players"); -- define players.
02 
03--//Backpack\\--
04 
05for i, v in pairs(Players.LocalPlayer.Backpack:GetChildren()) dp
06    if v:IsA("Tool") then
07        -- Tool found
08    end;
09end;
10 
11--//If Tool Is Equipped\\--
12 
13for i, v in pairs(Players.LocalPlayer.Character:GetChildren()) do
14    if v:IsA("Tool") then
15        -- Tool found
16    end;
17end;
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
01local Players = game:GetService:Players
02 
03for i,v in pairs(Players:GetPlayers()) do -- Check if tool is equipped for any player
04    for i,a in pairs(v.Character:GetChildren()) do
05        if a:IsA('Tool') then
06            print('A player with the name of  '..v.Name..' is holding a tool with the name of '..a.Name)
07end
08end
09end
10 
11for i,v in pairs(Players:GetPlayers()) do -- Check if tool is in a backpack for any player
12    for i,a in pairs(v:FindFirstChild('Backpack'):GetChildren()) do
13        if a:IsA('Tool') then
14            print('A player with the name of  '..v.Name..' has a tool with the name of '..a.Name..' in his backpack')
15end
16end
17end

Answer this question