Hello there!
I’m trying to create a surfaceGui that keeps track of the number of people who die. I want it to count only the number of deaths of people who fall through an invisible block, which triggers the counter to increase the number. How would I create something like this? Thanks!
1 Like
You could accomplish this with the Touched event:
local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
-- Update these
local SurfaceGui = Workspace:WaitForChild("SurfaceGui")
local Block = Workspace:WaitForChild("Part")
local deathCount = 0
local touches = {}
Block.Touched:Connect(function(object)
local player = Players:GetPlayerFromCharacter(object.Parent)
if (player and not touches[player]) then
-- Increment count
deathCount = deathCount + 1
-- You can update the text here
-- Example:
SurfaceGui.Frame.TextLabel.Text = string.format("Deaths: %s", deathCount)
-- Debounce so it does not fire multiple times
touches[player] = true
delay(1, function()
touches[player] = nil
end)
end
end)
5 Likes