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

How do fix this script so when one dummy is killed the next time I press U it kills the next dummy?

Asked by 5 years ago

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:

01local commandTest = game.Workspace.CommandTestDummies:FindFirstChild("KillTest")
02local userInput = game:GetService("UserInputService")
03local human = commandTest:FindFirstChild("Humanoid")
04 
05userInput.InputBegan:Connect(function(inputBegan, gameProccesed)
06    if inputBegan.KeyCode == Enum.KeyCode.U then
07        if human ~= nil then
08            human.Health = human.Health - 25
09        end
10    end
11end)

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Create "dummys" with a name followed by a number starting at 0.

01local Index = 0
02local commandTest = game.Workspace.CommandTestDummies:FindFirstChild("Name0")
03local userInput = game:GetService("UserInputService")
04local human = commandTest:FindFirstChild("Humanoid")
05 
06userInput.InputBegan:Connect(function(inputBegan, gameProccesed)
07    if inputBegan.KeyCode == Enum.KeyCode.U then
08        if human ~= nil then
09            human.Health = human.Health - 25
10    else
11        Index = Index + 1
12        commandTest = game.Workspace.CommandTestDummies:FindFirstChild("Name"..Index)
13        human = commandTest:FindFirstChild("Humanoid")
14        end
15    end
16end)
Ad

Answer this question