#spawn block that kills and waits 10 seconds before it can kill someone else

1 messages · Page 1 of 1 (latest)

strange bridge
#

This is my first time using luau coding, so I'm learning to code. For my first project, I wanted the spawn to kill players and then wait 10 seconds before being able to kill them again. But I don't know where my mistake is.

my code is :

function killPLayer(SpawnLocation)
local character = SpawnLocation.Parent

if character and character:IsA("Model") then
    local humanoid = character:FindFirstChildOfClass("Humanoid")
    if humanoid then
        humanoid:TakeDamage(humanoid.MaxHealth)
    end
end

end

script.Parent.Touched:Connect(killPLayer)

local killblock = false

script.Parent.TouchEnded:Connect(function(hit)
local character = hit.Parent
local humanoid = character:FindFirstChildOfClass("Humanoid")

if not humanoid and humanoid.Health <= 0 then return end
if killblock then return end
        
    killblock = true
    humanoid:TakeDamage(humanoid.MaxHealth)
    
    task.delay(10, function()
    killblock = false
end)

end)

I'm learning to code!
Thanks for the help!

crimson pond
#

well, whats not working about it?

inner carbon
#

killPLayer is not subject to any cooldown, it just instantly kills anything without a cooldown.

#

plz state the problem clearly next time Thumbs

strange bridge
grave dawn
#

like wait

#

dude what in the

#
local SpawnLocation = workspace.SpawnLocation
local Debounce = false

local Time = 10 -- Amount of time that will wait

SpawnLocation.Touched:Connect(function(hit)
    if not Debounce then -- Verify if the Debounce is active or not
        Debounce = true
        local Humanoid = hit.Parent:FindFirstChild("Humanoid") -- Gets the Humanoid
        
        Humanoid.Health = 0 -- Sets the Humanoid's Health to zero/Kill the Player
        
        task.wait(Time) -- This waits and its literally that :)

        Debounce = false
    end
end)

@strange bridge Here put the script in the SpawnLocation

#

Basically what u was doing is creating some functions that wasnt really necessary

#

and making variables that dont make sense

#

there is so much cool things and there

#

that will help you

crimson pond
inner carbon
crimson pond
#

ohhh wait nvm i see it there

strange bridge
#

@grave dawn thanks for the desolate code I was not at home, I will test the script when I am at home, and I will analyze it to learn, and thank you for your advice!