Hello! I am having trouble with randomly generating obstacles. I want it so that there is a chance that a light in a room will turn blue and if you walk under it it will kill you. This is in randomly generated rooms, and it seems that if one room has the light turn blue, they all do, instead of them all having a different outcome. Code:
local lightpart = script.Parent.LightPart
local area = script.Parent.DangerArea
local cursed = math.random(1,2)
local danger = false
if cursed == 2 then
lightpart.BrickColor = BrickColor.Blue()
danger = true
end
area.Touched:Connect(function(hit)
if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") and danger == true then
hit.Parent.Humanoid.Health = 0
end
end)
if danger == not true then
area:Destroy()
end
(50% chance for testing purposes)
I don’t know how to fix it, so any help would be appreciated!
area.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and danger == true then
hit.Parent.Humanoid.Health = 0
elseif danger == false then
area:Destroy()
end
end
end)