I’m trying to make an area so that when Life Support shuts down, players inside will get sick and start taking damage. I’ll use a ScreenGUI for the visual effects.
Sorry if I’m not being specific enough, please ask any questions you have!
I suppose a while loop could work.
Basically, when the players enter the area, the while loop will start checking if LifeSupportOn = true is, in fact, true. The moment LifeSupportOn is set to false, the loop will run whatever code you put inside it.
A little example in pseudo-code:
local LifeSupportOn = true --you'll decide how to set this variable. RemoteEvents are your friend.
while LifeSupportOn == false do
Humanoid:TakeDamage(10)
task.wait(1) -- yielding is necessary or else the players will die in less than a second.
end
You can use OverlapParams to check if players are inside the area or, better, the Zone+ module you can find by seaching on Google.
No. Specifically what I’m trying for is:
When Life Support fails, gas will begin leaking from the vents (already scripted). If LS is not rebooted within an amount of time, the “pain zone” kicks into effect. Anyone inside the pain zone will start to have weird vision (ScreenGUI) and then they take damage, unless of course they are able to reboot the system before dying.
Here’s a somewhat short example to get you started, it’ll require a physical part instance to represent the damaging area.
local Game = game
local Workspace = workspace
local Players = Game:GetService("Players")
local RunService = Game:GetService("RunService")
local Part = Workspace.Part --Harmful area.
local Time = 0
local function OnHeartbeat(Delta)
if Time > 10 then Time = 0 else Time += Delta return end --Frequency of 'ticks', currently once per 10 seconds.
local Models = {}
local Parts = Workspace:GetPartsInPart(Part)
for _, Part in ipairs(Parts) do
local Model = Part:FindFirstAncestorOfClass("Model")
if (not Model) or Models[Model] then continue end
Models[Model] = true
local Humanoid = Model:FindFirstChildOfClass("Humanoid")
if (not Humanoid) or Humanoid.Health <= 0 then continue end
local Player = Players:GetPlayerFromCharacter(Model)
if not Player then continue end
Humanoid:TakeDamage(10) --Damage per 'tick', currently 10.
end
end
RunService.Heartbeat:Connect(OnHeartbeat)
You’re a genius! Although I don’t understand a thing of this script, it works magnificently and I’ll try my best to decipher what I can for future coding of my own.
Thanks for the help! This is one step closer to the very far away finishing line of my game.