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.
01 | local replicatedStorage = game:GetService( "ReplicatedStorage" ) |
02 | local remoteData = game:GetService( "ServerStorage" ):WaitForChild( "RemoteData" ) |
03 | local starterRebirthAmount = 100 |
06 | replicatedStorage.Remotes.Lift.OnServerEvent:Connect( function (player) |
07 | if not remoteData:FindFirstChild(player.Name) then return "NoFolder" end |
09 | local debounce = remoteData [ player.Name ] .Debounce |
11 | if not debounce.Value then |
13 | local Animation = Instance.new( "Animation" ) |
16 | local LoadedAnimation = game.Workspace [ player.Name ] .Humanoid:LoadAnimation(Animation) |
17 | LoadedAnimation:Play() |
18 | local toolsInPackpack = game.Workspace [ player.Name ] :GetChildren() |
19 | local enTool = game.Workspace [ player.Name ] :FindFirstChildOfClass( "Tool" ) |
22 | for i,v in pairs (toolsInPackpack) do |
23 | print (v.Name..v.ClassName) |
24 | if v.ClassName = = "Tool" then |
26 | if game.Workspace [ player.Name ] then |
28 | local char = game.Workspace [ player.Name ] |
29 | if v:findFirstChild( "Weight" ) then |
31 | local weight = v:findFirstChild( "Weight" ) |
32 | if weight.Value = = 0 then |
33 | player.leaderstats.Strength.Value = player.leaderstats.Strength.Value+ 10 *(player.leaderstats.Rebirths.Value + 1 ) |
34 | elseif weight.Value = = 1 then |
35 | player.leaderstats.Strength.Value = player.leaderstats.Strength.Value+ 20 *(player.leaderstats.Rebirths.Value + 1 ) |
36 | elseif weight.Value = = 2 then |
37 | player.leaderstats.Strength.Value = player.leaderstats.Strength.Value+ 40 *(player.leaderstats.Rebirths.Value + 1 ) |
38 | elseif weight.Value = = 3 then |
39 | player.leaderstats.Strength.Value = player.leaderstats.Strength.Value+ 90 *(player.leaderstats.Rebirths.Value + 1 ) |
40 | elseif weight.Value = = 4 then |
41 | player.leaderstats.Strength.Value = player.leaderstats.Strength.Value+ 150 *(player.leaderstats.Rebirths.Value + 1 ) |
50 | debounce.Value = false |