local screenGui = script.Parent
local remoteEvent = game.ReplicatedStorage.Events.TimerEnd
local countdownLabel = script.Parent.TextLabel
local countdown = 15
local function updateCountdown()
countdown = countdown - 1
countdownLabel.Text = countdown
if countdown <= 0 then
remoteEvent:FireServer(game.Players.LocalPlayer)
end
end
while true do
updateCountdown()
wait(1)
end
Script
local remoteEvent = game.ReplicatedStorage.Events.TimerEnd
function remoteEvent.OnServerEvent(player)
local humanoid = player.Character:WaitForChild("Humanoid")
humanoid:Die()
end
I’m trying to make a timer so that when the timer ends, it kills the player
The timer itself works, but it goes to the negatives, and it doesn’t kill the player
The “:” means it will pass the object itself as the first argument (self), in this case humanoid. Now :Die() is not a method of humanoid. With a function as you suggest it would look more like Die(humanoid)
This isn’t halting the counter. This is checking if countdown is 0 or smaller, and if so, it’s firing your event. You could add a return, although I’d probably just change it to an if-else
I don’t know if anybody has said this yet, but you don’t need to fire the player as an argument. It is automatically the first argument on the server side.
local screenGui = script.Parent
local remoteEvent = game.ReplicatedStorage.Events.TimerEnd
local countdownLabel = script.Parent.TextLabel
local countdown = 15
while true do
countdown -= 1
countdownLabel.Text = countdown
if countdown <= 0 then
remoteEvent:FireServer(game.Players.LocalPlayer)
break
end
task.wait(1)
end
Script:
local remoteEvent = game.ReplicatedStorage.Events.TimerEnd
remoteEvent.OnServerEvent:Connect(function(player)
local humanoid = player.Character:WaitForChild("Humanoid")
humanoid.Health = 0
end)