Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago
Edited 2 years ago

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

0
Damn and what is with assuming the players gender lol bailley5 114 — 2y

1 answer

Log in to vote
0
Answered by
enes223 327 Moderation Voter
2 years ago
Edited 2 years ago

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
0
Thank you i will try... oldmantv12345 9 — 2y
0
And where i put script? In folder or serverscriptservice? oldmantv12345 9 — 2y
0
serverscriptservice would be nice enes223 327 — 2y
0
ok and can you make script if player will not turn lights on then he will die? :D It will be nice oldmantv12345 9 — 2y
View all comments (5 more)
0
I can't make this work for specific players, this is global for all lights in the "Light" folder. enes223 327 — 2y
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 ... oldmantv12345 9 — 2y
0
Add me on Discord, MrEAZL#9118 enes223 327 — 2y
0
I think i have something wrong i will check it oldmantv12345 9 — 2y
0
ok oldmantv12345 9 — 2y
Ad

Answer this question