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 4 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:

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)

1 answer

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

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)


Ad

Answer this question