-- Game of red light green light (don't move when red!)local lightIsGreen =false-- Toggle from red to green and green to redfunctionswapLightColor()local nextLightColorIsGreen =not lightIsGreenlocal lightColor ="GREEN"ifnot nextLightColorIsGreen then lightColor ="RED"end MessageService.broadcast("Light changed: " .. lightColor .."!")-- Wait briefly before changing to "red"if lightIsGreen then task.wait(1)end-- Swap light color lightIsGreen = nextLightColorIsGreenendfunctiongetLightWaitTime()local waitTime =1.5+math.random() *4if lightIsGreen then waitTime =5+math.random() *5endreturn waitTimeend-- Function to change light color on an intervalfunctionstartLightLoop()while (task.wait(getLightWaitTime())) do swapLightColor()endendlocal lastPlayerPosition = {}-- Function to constantly check if a player has movedfunctionstartMovementLoop()while task.wait(0.1) dofor i, player in PlayerService.getPlayers() dolocal entity = player:getEntity()ifnot entity then lastPlayerPosition[player] =nil continueend-- Check if player moved when light is redifnot lightIsGreen and lastPlayerPosition[player] ~=nilthenlocal distance = lastPlayerPosition[player] - entity:getPosition()if distance.Magnitude >3then CombatService.damage(entity, 100)endendif lightIsGreen then lastPlayerPosition[player] = entity:getPosition()endendendendtask.spawn(startLightLoop)task.spawn(startMovementLoop)
Deals the specified amount of damage to an entity. Use the optional fromEntity parameter to specify the source of the damage. Use the optional knockback parameter to specify the applied knockback multipliers.