Hi all
i am making a horror game in which a player can only turn on there flashlight at certain time of day.
But when i try to implement this into the script it is not working.I really don’t know why this is happening
i was wondering if any one can help me.
Here’s the script
local mouse = game.Players.LocalPlayer:GetMouse()
function Light()
local player = game.Players.LocalPlayer
local playerChar = player.Character
local playerLight = playerChar.Head:FindFirstChild("Light")
if playerLight then
playerLight:Destroy()
else
local light = Instance.new("SurfaceLight",playerChar:FindFirstChild("Head"))
light.Name = "Light"
light.Range = 60
light.Angle = 60
light.Shadows = true
light.Brightness = 5
end
end
if game.Lighting.TimeOfDay == "13:00:00" then
mouse.KeyDown:connect(function(key)
key = key:lower()
if key == "f" then
script.Sound:Play()
Light()
end
end)
end
Please don’t post the same topic twice, you asked this exact question a while ago and got a good answer.
Your script is only successful at exactly “13:00:00”, or 1 o’clock in the afternoon. Then it allows a change if the player clicks their mousebutton.
You need to make it function every time they click their mousebutton and check to see if the GetMinutesAfterMidnight (not TimeOfDay) is in a range where it would be useful. If you need it from 13:00 to 14:00 then use this:
mouse.KeyDown:connect(function(key) -- see the note below
if game.Lighting.GetMinutesAfterMidnight() > 13 * 60 or game.Lighting.GetMinutesAfterMidnight() > 14 * 60 then
-- allow flashlight to turn on with mouseclick, or use UserInputService to see if the player clicks the letter F.
end