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
You need to put mousedown before the if statement, like this:
mouse.KeyDown:connect(function(key)
if game.Lighting.TimeOfDay == "13:00:00" then
key = key:lower()
if key == "f" then
script.Sound:Play()
Light()
end
end
end)
Also, that 13:00:00 is too specific. Consider it being between a timeframe like 8:00:00 to 20:00:00.
̶M̶o̶u̶s̶e̶d̶o̶w̶n̶ ̶i̶s̶ ̶N̶O̶T̶ ̶u̶s̶e̶d̶ ̶f̶o̶r̶ ̶k̶e̶y̶s̶,̶ ̶s̶o̶ ̶i̶ ̶d̶o̶n̶’̶t̶ ̶k̶n̶o̶w̶ ̶w̶h̶y̶ ̶y̶o̶u̶’̶r̶e̶ ̶p̶u̶t̶t̶i̶n̶g̶ ̶a̶ ̶k̶e̶y̶ ̶v̶a̶r̶i̶a̶b̶l̶e̶ ̶i̶n̶ ̶k̶e̶y̶d̶o̶w̶n̶?̶
So considering this all in mind, it would look like this:
(I did not test it)
local UserInputService = game:GetService("UserInputService")
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
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then
if input.KeyCode == Enum.KeyCode.F then
if game.Lighting.TimeOfDay == "13:00:00" then --Or game.Lighting.Clocktime >= 8 and game.Lighting.Clocktime <= 20
script.Sound:Play()
Light()
end
end
end
end)
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then
if input.KeyCode == Enum.KeyCode.F then
if game.Lighting.TimeOfDay == "13:00:00" then --Or game.Lighting.Clocktime >= 8 and game.Lighting.Clocktime <= 20
script.Sound:Play()
Light()
end
end
end
end)