My goal is to create a short script that kills a player after all the required parts have been destroyed. This is done by stepping on a trigger (Trigger2) to destroy all parts. Now, the part of the code I have at line 33 does end up killing my character, but that's simply because it makes sense (Because 3 minus 3 does equal to 0. In this case, that would be "myarray" - "myarray" = "emptytable") . Instead, I want to create a function that keeps track of the remaining parts (Touch1, Touch2, and Touch3), but I don't know how to.
local Touch1 = game.Workspace.Touch1
local Touch2 = game.Workspace.Touch2
local Touch3 = game.Workspace.Touch3
local player = game.Players.LocalPlayer
local myarray = {workspace.Touch1, workspace.Touch2, workspace.Touch3}
local emptytable = {}
debounce = false
function message()
local m = Instance.new("Message", workspace)
m.Text = "Touch the trigger to die"
wait(2.5)
m:remove()
end
message()
function OnTouched()
if debounce == true then return end
debounce = true
for i,v in pairs(myarray) do
Touch1:destroy()
wait()
Touch2:destroy()
wait()
Touch3:destroy()
end
**if #myarray - 3 == #emptytable then -- this is the part that I don't like. Want to change**
game.Players.LocalPlayer.Character.Humanoid:TakeDamage(100)
end
end
game.Workspace.Trigger2.Touched:connect(OnTouched)

1 comment
thanks so much.