Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make a script that turns light off and then player needs to turn lights on?

All I need is a script that turns off the lights every 30 seconds and the player will have to turn them on manually via the proximityprompt. Player will have only 15 seconds to do it. So if he doesn't turn them on, he will die. And immediately the script resets so it will have 30 seconds again to check the cameras and watch the monster that moves there. And like this all the time. I already have a teleporting monster and cameras but i am not scripter so i cant do this script... :( Please someone help me... I will be very happy!

Thank you for helping. Rohlik1234567890

1 comment

0

Damn and what is with assuming the players gender lol

1 answer

✓ Accepted answer

First, you will need lamp models, inside the models you will need a light instance, if you set it up according to my script it will be easier, make a model then make an Attachment (Or anything else that holds the light instance) named "LightHolder", then put SpotLight or any light source in it, also if you want a switch with it make a switch model then name the clickable part "SwitchPart" then put a ClickDetector inside it, group the switch model and the light model together and name them "LightModel" and "SwitchModel" then put it in a Folder named "Lights" in the workspace, the script (Edited my answer because there was something wrong):

local Lights = workspace:WaitForChild("Lights")
local WaitTime = 30 -- You can configure how many seconds need to pass to turn off the light

for _,LightGroup in pairs(Lights:GetChildren()) do
	local Light = LightGroup.LightModel.LightHolder.Light
	local Detector = LightGroup.SwitchModel.SwitchPart.ClickDetector

	Detector.MouseClick:Connect(function()
		if Light.Enabled then
			Light.Enabled = false
		else
			Light.Enabled = true
			local i = 0 -- We set a variable so we can count how many seconds passed
			repeat -- We repeat until 30 seconds is up
				if Light.Enabled == false then -- If the light is already turned off return so it won't turn off randomly after turning on
					return
				end
				i = i + 0.1
				task.wait(0.1) -- task.wait is guaranteed to run the next frame unlike normal wait
			until i >= WaitTime
			Light.Enabled = false
		end
	end)

	if Light.Enabled then
		local i = 0
		repeat
			if Light.Enabled == false then
				return
			end
			i = i + 0.1
			task.wait(0.1)
		until i >= WaitTime
		Light.Enabled = false
	end
end

9 comments

0

Thank you i will try...

0

And where i put script? In folder or serverscriptservice?

0

serverscriptservice would be nice

0

ok and can you make script if player will not turn lights on then he will die? :D It will be nice

0

I can't make this work for specific players, this is global for all lights in the "Light" folder.

0

Does the script have to turn off the lights after 30 seconds and the player has to turn them on? Because it hasn't done anything yet and I think I have everything right ...

0

Add me on Discord, MrEAZL#9118

0

I think i have something wrong i will check it

0

ok

This discussion is preserved as it was. New answers, comments, and votes are closed.