How do I make a bed that works only at nightime

So I need help making a bed that makes you sleep at night time. But whenever it’s daytime and you trigger the proximity prompt I made a script that shows you text telling you, you shouldn’t sleep. I wanna make it so that text can disappear and the screen fades to black when the proximity prompt is triggered. (Sorry for bad english)

4 Likes

Which part are you having trouble with? Have you seen Lighting.ClockTime?

2 Likes

Yeah I tried using a script using that but it didn’t work so I deleted it.

1 Like

Could you share what you tried and what about it wasn’t working?

2 Likes

To make the text disappear and the screen fade to black, you could try using TweenService.

The disappearing text could be achieved by tweening the text’s TextTransparency to 1 (unless you want the text to instantly disappear, then instead of tweening you can replace it with just setting the TextTransparency to 1).

As for the screen fading to black, you could make an empty Frame that covers the whole entire screen. Set the BackgroundColor to black, and set the BackgroundTransparency to 1. When you fade the screen, tween the BackgroundTransparency to 0 to make the screen black.

Okay I’ll try this and let you know if I have any issues.

local ProximityPrompt = script.Parent:FindFirstChild("ProximityPrompt")
local BadgeService = game:GetService("BadgeService") 

local badgeID = 2150203040

local function UpdateProximityPromptText(timeOfDay)
    if timeOfDay >= 18 or timeOfDay <= 6 then
        ProximityPrompt.ObjectText = "Sleep"
    else
        ProximityPrompt.ObjectText = "..."
    end
end

function ShowBlackScreen(player)
    local playerGui = player:FindFirstChild("PlayerGui")
    if playerGui then
        local blackScreen = Instance.new("Frame")
        blackScreen.Size = UDim2.new(1, 0, 1, 0)
        blackScreen.Position = UDim2.new(0, 0, 0, 0)
        blackScreen.BackgroundColor3 = Color3.new(0, 0, 0)
        blackScreen.BackgroundTransparency = 0.9
        blackScreen.ZIndex = 10
        blackScreen.Parent = playerGui
        wait(5)
        blackScreen:Destroy()
    end
end

ProximityPrompt.Triggered:Connect(function(player)
    local timeOfDay = game.Lighting:GetMinutesAfterMidnight() / 60
    if timeOfDay >= 18 or timeOfDay <= 6 then
        ShowBlackScreen(player)
        
        local success, errorMessage = pcall(function()
            BadgeService:AwardBadge(player.UserId, badgeID)
        end)

        if not success then
            warn("Badge awarding failed:", errorMessage)
        else
            print("Badge awarded successfully to", player.Name)
        end
    end
end)

while true do
    local timeOfDay = game.Lighting:GetMinutesAfterMidnight() / 60
    UpdateProximityPromptText(timeOfDay)
    wait(60)
end

I also made it so a badge can be awarded