Tool giver but it a cooldown

I am trying to find a way where I could make a tool giver (a gun) where you touch the model/part and it gives you the tool, but it disappears for a period of time and it appears back again. Any ideas? I would appreciate some codes

1 Like

Do you have any examples of the code to begin with?

local ToolGiverPart = script.Parent.ToolGiverPart
local Tool = game.ServerStorage:FindFirstChild(“YourToolName”)

local toolGiven = false

ToolGiverPart.Touched:Connect(function(part)
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if player and not toolGiven then
toolGiven = true
local toolClone = Tool:Clone()
toolClone.Parent = player.Backpack

    ToolGiverPart.Transparency = 1 -- Hide the tool giver part
    ToolGiverPart.CanCollide = false

    wait(180) -- Wait for 3 minutes

    ToolGiverPart.Transparency = 0 -- Show the tool giver part again
    ToolGiverPart.CanCollide = true

    if toolClone.Parent == player.Backpack then
        toolClone:Destroy()
    end

    toolGiven = false
end

end)

	local ToolGiverPart = script.Parent.ToolGiverPart
	local Tool = game.ServerStorage:FindFirstChild("YourToolName")
	local debounce = false -- What we'll use to prevent spamming
	local toolGiven = false
	
	ToolGiverPart.Touched:Connect(function(part)
		local player = game.Players:GetPlayerFromCharacter(part.Parent)
		if player and not toolGiven and debounce == false  then
			toolGiven = true
			debounce = true
			local toolClone = Tool:Clone()
			toolClone.Parent = player.Backpack
	
			ToolGiverPart.Transparency = 1 -- Hide the tool giver part
			ToolGiverPart.CanCollide = false
	
			wait(180) -- Wait for 3 minutes
	
			ToolGiverPart.Transparency = 0 -- Show the tool giver part again
			ToolGiverPart.CanCollide = true
	
			if toolClone.Parent == player.Backpack then
				toolClone:Destroy()
			end
	debounce = false -- After the 3 minutes above, set the debounce to false at the end of the function.
			toolGiven = false
		end
	end)

Super dope, will sure check this out. Thanks a lot!!

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