How to make a part spawn at a specific time & for a specific time once a day?

Basically, I wanted to make a coin in replicatedstorage spawn at a specific place in-game for 10 minutes only at 6 PM EST everyday, and I wanted to make it so that only 1 player can get it, so once it spawns only one player can touch the coin and the player that touches it first only gets a specific badge, so when that someone gets it, it despawns and only spawns again at 6 PM EST the other day. How can I make this?

I barely have any scripting knowledge, but this is what I got so far (I’m not sure how to implement the Date/Time stuff)

ServerScript under ServerScriptService (Main script):

local rs = game:GetService("ReplicatedStorage")
local coin = rs:WaitForChild("WhiteCoin") 
local remote = rs.Remotes.AwardWhiteCoinBadge
local pos = game.Workspace:WaitForChild("WhiteCoinTP")


	coin.Parent = workspace
	coin.Touched:Connect(function(part)
		if part.Parent:FindFirstChild("Humanoid") then
			remote:FireServer()
		end
	end)

	task.wait(10)
	
	coin.Parent = rs

ServerScript in ServerScriptService (Handles the badge award, via using RemoveEvent in ReplicatedStorage):

local whiteCoinRemote = game.ReplicatedStorage.Remotes.AwardWhiteCoinBadge

whiteCoinRemote.OnServerEvent:Connect(function(player)
	game.BadgeService:AwardBadge(player.UserId,1088875429822925)
end)
4 Likes

You should be able to achieve this using os.date

local rs = game:GetService("ReplicatedStorage")
local coin = rs:WaitForChild("WhiteCoin") 
local remote = rs.Remotes.AwardWhiteCoinBadge
local pos = game.Workspace:WaitForChild("WhiteCoinTP")

while task.wait(1) do
        local currentDate = os.date("*t")
        if currentDate.hour == 18 and currentDate.min == 0 then
	        coin.Parent = workspace
	        coin.Touched:Connect(function(part)
		    if part.Parent:FindFirstChild("Humanoid") then
		    	remote:FireServer()
		    end
	    end)

	    task.wait(600)
	
	    coin.Parent = rs
end
1 Like

It spawning seems to be working, but I get this error:
RobloxStudioBeta_zO66eLJ9Xr

Which I assume prevents me from getting the badge.

Also is it possible to make it so that, it disappears after 10 minutes (which is what it does now), or if someone collects it? (so when someone touches it, It despawns without needing to wait 10 minutes)

2 Likes

You can only fire a message to the server from a local script, much like you can only fire a message to the client from a server script.

As for making it disappear when touched, we’ll just parent it to rs on contact

ServerScript:

local rs = game:GetService("ReplicatedStorage")
local coin = rs:WaitForChild("WhiteCoin") 
local remote = rs.Remotes.AwardWhiteCoinBadge
local pos = game.Workspace:WaitForChild("WhiteCoinTP")

while task.wait(1) do
        local currentDate = os.date("*t")
        if currentDate.hour == 18 and currentDate.min == 0 then
	        coin.Parent = workspace
	        coin.Touched:Connect(function(part)
		    if part.Parent:FindFirstChild("Humanoid") then
		    	remote:FireAllClients(game.Players:GetPlayerFromCharacter(part.Parent))
                coin.Parent = rs
		    end
	    end)

	    task.wait(600)
	
	    coin.Parent = rs
end

LocalScript:

local whiteCoinRemote = game.ReplicatedStorage.Remotes.AwardWhiteCoinBadge

whiteCoinRemote.OnClientEvent:Connect(function(player)
    if player = game.Players.LocalPlayer then
	    game.BadgeService:AwardBadge(player.UserId,1088875429822925)
    end
end)
1 Like

Thank you! One last question, where should I place the localscript? Because it was previously a serverscript under serverscriptservice

Try placing it in StarterPlayer > StarterPlayerScripts.

2 Likes

Oh thats weird, no errors in output but in-game I didn’t get the badge even after touching it

1 Like

Although it showed this in studio, so I thought it should award the badge in-game
RobloxStudioBeta_VYGYLJ3fcL

Certain services, such as badge awarding and teleport service can only be done in roblox game servers, not studio.

The warning only lets you know about it, but it does indicate that it does function properly, and shouldn’t cause any issues ingame.

1 Like

I understand, but for some reason when I touch the coin in-game, I still don’t get awarded the badge.

EDIT: Actually it shows this error in dev console (client):
RobloxPlayerBeta_ZfUu4wxCtt

I think that it’s implying that the badge can only be rewarded on a server script.

Try creating another RemoteEvent and fire the UserID and badge ID to the server.

local whiteCoinRemote = game.ReplicatedStorage.Remotes.AwardWhiteCoinBadge

whiteCoinRemote.OnClientEvent:Connect(function(player)
    if player = game.Players.LocalPlayer then
	    game.ReplicatedStorage.BadgeAwarder:FireServer(player.UserId, 1088875429822925)
    end
end)

Place this into a server script (probably in ServerScriptService)

game.ReplicatedStorage.BadgeAwarder.OnServerEvent:Connect(function(Player, userID, badgeID)
    game.BadgeService:AwardBadge(userID, badgeID)
end)

This probably isn’t the most efficient way to do this, but it should work in the long run.

1 Like

Worked perfectly, THANK YOU SO MUCH!!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.