Give item to everybody at a certain time for a certain amount of time

Hi,
So i want to make a script that gives people an item every lets say 200 seconds, for 30 seconds, then deletes the item from inventory.

Please, any help appreciated.

You mean something like this?

local tool = --tool

while task.wait(200) do
    for i,v in pairs(game.Players:GetPlayers()) do
        tool:Clone().Parent = v.Backpack
    end
    task.wait(30)
    for i,v in pairs(game.Players:GetPlayers()) do
        local plrtool = v.Backpack:FindFirstChild(tool.Name) or v.Character:FindFirstChild(tool.Name)
        if tool then 
            tool:Destroy()
        end
    end
end

Quick question: Where would i put this script so i make sure it works?

Wherever you want honestly. Just put it in ServerScriptService as a normal script though. Also, make sure to reference the tool.

Does not delete the tool sadley.

Are there any errors? It seems like this would worl perfectly fine.

No errors, it does not delete the tool in question but adds another after it repeats?

Oh, my bad, I was referencing the wrong thing at the end.

local tool = --tool

while task.wait(200) do
    for i,v in pairs(game.Players:GetPlayers()) do
        tool:Clone().Parent = v.Backpack
    end
    task.wait(30)
    for i,v in pairs(game.Players:GetPlayers()) do
        local plrtool = v.Backpack:FindFirstChild(tool.Name) or v.Character:FindFirstChild(tool.Name)
        if plrtool then 
            plrtool:Destroy()
        end
    end
end

It removes the tool permanently when i die. I want it to stay until the 30 seconds ended even if died.

Otherwise this works. Thanks for that.

Then simply put it into startergear.

local tool = --tool

while task.wait(200) do
    for i,v in pairs(game.Players:GetPlayers()) do
        tool:Clone().Parent = v.Backpack
        tool:Clone().Parent = v.StarterGear
    end
    task.wait(30)
    for i,v in pairs(game.Players:GetPlayers()) do
        local plrtool = v.Backpack:FindFirstChild(tool.Name) or v.Character:FindFirstChild(tool.Name)
        if plrtool then 
            plrtool:Destroy()
        end
        v.StarterGear:FindFirstChild(tool.Name):Destroy()
    end
end

Realized it would only destroy the one in StarterGear if the player had the tool so had to fix that

1 Like

Works exactly how i wanted. Unfortunately, the tool i was talking about does not work how i wanted, but ill just find another. By the way, how would i make a message appear (textlabel) when this event happens?

I would want the text of it to change, its already in starter GUI, too.

I would probably use :FireAllClients and a remote event ex:

local tool = --tool
local event = --event

while task.wait(200) do
    for i,v in pairs(game.Players:GetPlayers()) do
        tool:Clone().Parent = v.Backpack
        tool:Clone().Parent = v.StarterGear
    end
    event:FireAllClients()
    task.wait(30)
    for i,v in pairs(game.Players:GetPlayers()) do
        local plrtool = v.Backpack:FindFirstChild(tool.Name) or v.Character:FindFirstChild(tool.Name)
        if plrtool then 
            plrtool:Destroy()
        end
        v.StarterGear:FindFirstChild(tool.Name):Destroy()
    end
end

local script:

local event = --event
local label = --label to change

event.OnClientEvent:Connect(function()
    label.Text = "whatever here"
end)

Would i put the local script in starter UI?

Yes, you need it to be in a place that the client can receive information.

And this will show for all players, right? also, sorry for so many questions, i get very confused with studio.

Yes, it will show for all players that are currently in the game.

It wont delete the tool now, and i have no idea why.

It is a crossbow from the toolbox, i set the name, everything.