Comment on page
🤝
Events
Events allow you to provide a function that will be run when an action occurs:
-- Execute entities when their health falls under 20
Events.EntityDamage(function(event)
if (event.entity:getHealth() < 20) then
event.entity.kill()
end
end)
You can also modify (or sometimes cancel) event data:
-- Double all damage in the game after 15 minutes
Events.EntityDamage(function(event)
local matchDurationSec = MatchService:getMatchDurationSec()
if (matchDurationSec > 15 * 60) then
event.damage = event.damage * 2
end
end)
WARNING: Yielding in an event will delay the outcome of the event. Examples of yielding include
task.wait()
, while loops, using DataStoreService, or iterating over a very large set of objects.It is highly recommended to use
task.spawn()
when waiting in an event.Last modified 3mo ago