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)
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
It spawning seems to be working, but I get this error:
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)
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)
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)