How can i make Reward for 1 hour played

Hello, i’m needing a script for user will play my game and after 1 hour the game will give a gear for played 1 hour. I searched for this but everything daily reward or just cash rewarding…

I want just give them a gear for played one hour. Can someone help about that?

Thanks…

2 Likes
local plrs = game:GetService("Players")

plrs.PlayerAdded:Connect(function(p)
  wait((60 * 60) * 60) -- lol forgot how much seconds in a hour
  if typeof(p) == "Instance" then
    -- cool stuff
    p:Kick('r u sleeping or something')
  end
end)
1 Like

What makes p:kick when it kicking and what reason

and should it be local script or

local Players = game:GetService("Players") 
Players.PlayerAdded:Connect(function(Player) 
wait(3600) 
print("Here is your reward") 
end) 

It should be in Script inside ServerScriptService

2 Likes

How can i add there gear in replicated stroge? can u make example pls

1 Like

Do you mean gear or tool? But basically you will do something like this:

local Players = game:GetService("Players") 
Players.PlayerAdded:Connect(function(Player) 
wait(3600) 
local Gear = game:GetService("ReplicatedStorage").Gear:Clone() 
Gear.Parent = Player.Character
end)
1 Like

I tried it right now but the gear / tool stays for 2 second and it going back from inventory ? why ?

1 Like

Can you show me your code, please?

1 Like

local Players = game:GetService(“Players”)
Players.PlayerAdded:Connect(function(Player)
wait(15)
local Gear = game:GetService(“ServerStorage”).Carpet:Clone()
Gear.Parent = Player.Character
end)

after 15second i get carpet tool in server storage to inventory then 2 second later it removing

1 Like

This is your full code isn’t possible that something is trying to set the parent back?

1 Like

Weird, okay thank you ! i’ll check it

2 Likes

You have to put it into the backpack and startergear.

local Players = game:GetService("Players") 

Players.PlayerAdded:Connect(function(Player) 
    wait(3600) 
    local Gear, Gear1 = game:GetService("ReplicatedStorage").Gear:Clone(), game:GetService("ReplicatedStorage").Gear:Clone() 
    Gear.Parent = Player.Backpack
    Gear1.Parent = Player.StarterGear
end)
1 Like

No,He want to make the player get gear from the moment they reach 1 hour,So after the first player reach one hour,New player would get the same gear.

1 Like

@iQeeDEVS didn’t mention what is gear if it’s tool or something else that’s why I don’t clone it to Backpack and StarterGear.

1 Like

You can use Players | Roblox Creator Documentation to achieve this.
Here’s an example:

local Players = game:GetService('Players')
local Gear = game:GetService('ReplicatedStorage').Gear


local function PlayerAdded(Player)
	wait(3600) -- Waits for 1 hour (3600 seconds), then reads the next lines afterwards
	if not Player then return end -- Check if the player still exists after one hour, in case they left, which will return nil if so.
	local Backpack = Player:FindFirstChild('Backpack')
	local StarterGear = Player:FindFirstChild('StarterGear')
	if not Backpack or not StarterGear then return end
	Gear:Clone().Parent = Backpack
	Gear:Clone().Parent = StarterGear
end


local GetPlayers = Players:GetPlayers()
for i = 1, #GetPlayers do
	coroutine.resume(coroutine.create(function()
		PlayerAdded(GetPlayers[i]) 
		-- Runs this function in parallel for every player.
		-- Unlike spawn(), coroutines does not have a built-in wait().
	end))
end
Players.PlayerAdded:Connect(PlayerAdded) -- Listen for new players to join.
2 Likes

thanks guys so much i made it !!

1 Like

Hello!

Before I start, I would like to say that I will be correcting the things said by the others here.

@p49p0 You don’t need to use typeof because the PlayerAdded function will get the player.

@caviarbro I don’t think this would be a good idea because exploiters can clone the gear, which is unfair. Moving it into the ServerStorage service will be a better option.

@VisaProxy same thing for you as well.

And everyone in the topic, using a data store that stores an integer and bool value is better to use because imagine the player was quitting the server without getting the reward. So they had had to wait again. Saving it won’t make the player wait for the reward.

I hope this script helps you.

local DataStoreService = game:GetService("DataStoreService")
local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")

local HourAchieved = DataStoreService:GetDataStore("HourAchieved")

Players.PlayerAdded:Connect(function(plr)


    local IntValue = Instance.new("IntValue", plr)
    IntValue.Name = "HourPlayed"

    local BoolValue = Instance.new("BoolValue", plr)
    BoolValue.Name = "IsAchieved"

    local Gear = ServerStorage.Gear
    local list

    local s, e = pcall(function()
	    list = HourAchieved:GetAsync(plr.UserId)
    end)

    if s then
	    if list ~= nil then
		    if list[1] then
			    Gear:Clone().Parent = plr.Character
			    IntValue.Value = list[2]
			    BoolValue.Value = true
			    return print(plr.Name .. " had taken the reward already.")
			
		    elseif not list[1] then
			    IntValue.Value = list[2]
			    print(plr.Name .. " doesn't have that reward.")
		    end
	    else
		    print(plr.Name .. " is new to the game.")
	    end
    else
	    warn("Couldn't load the data for " .. plr.Name, "\n" .. e)
    end

    while wait(1) and IntValue.Value < 3600 do
	    IntValue.Value += 1
    end

    print(plr.Name .. " achieved the reward.")

    BoolValue.Value = true

    if not plr.Character:FindFirstChild("Gear") then
	    Gear:Clone().Parent = plr.Character
    end

end)

Players.PlayerRemoving:Connect(function(plr)
    local s, e = pcall(function()
	    HourAchieved:SetAsync(plr.UserId, {
		    plr.IsAchieved.Value,
		    plr.HourPlayed.Value
	    })
    end)
end)

game:BindToClose(function()
    for i, plr in pairs (Players:GetPlayers()) do
	    local s, e = pcall(function()
	    HourAchieved:SetAsync(plr.UserId, {
		    plr.IsAchieved.Value,
		    plr.HourPlayed.Value
		    })
	    end)
    end
end)

This was tested.

1 Like

Hello,
can you tell me how would you award the player then? I didn’t know where is the “Gear” located and just thought about ReplicatedStorage + your item system shouldn’t relly on the item itself but on server side script that is giving you abilities when you are holding it because when you award the player with the gear, exploiter can stole the Item from the character model inside workspace if it’s tool or basically something that you want to be held within player so others can see it. So it is not big deal where you store the “Gear”.

For the consequences of exploiters cloning it, to provide maximum security, this would be better anyway. Suppose that there was no player in the server, which didn’t take the reward yet. This will prevent them for cloning it. I don’t say it can’t be stoppable forever but this is a precaution.