I made a script where when you press U, it damages one of the dummies. However, the problem is that it only damages one dummy and not any other. How do I fix this script?
The script:
local commandTest = game.Workspace.CommandTestDummies:FindFirstChild("KillTest") local userInput = game:GetService("UserInputService") local human = commandTest:FindFirstChild("Humanoid") userInput.InputBegan:Connect(function(inputBegan, gameProccesed) if inputBegan.KeyCode == Enum.KeyCode.U then if human ~= nil then human.Health = human.Health - 25 end end end)
Create "dummys" with a name followed by a number starting at 0.
local Index = 0 local commandTest = game.Workspace.CommandTestDummies:FindFirstChild("Name0") local userInput = game:GetService("UserInputService") local human = commandTest:FindFirstChild("Humanoid") userInput.InputBegan:Connect(function(inputBegan, gameProccesed) if inputBegan.KeyCode == Enum.KeyCode.U then if human ~= nil then human.Health = human.Health - 25 else Index = Index + 1 commandTest = game.Workspace.CommandTestDummies:FindFirstChild("Name"..Index) human = commandTest:FindFirstChild("Humanoid") end end end)