Cooldown doesnt work + starterpack doesnt work too

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I want to make cooldown so it doesnt damage or knockback too fast

  1. What is the issue? Include screenshots / videos if possible!

It simply doesnt work, I can spam click to insta kill the character

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I tried checking if im using right instances or making the cooldown set to true only in touched event, but nothing changed

Here’s the script

local rs = game:GetService("ReplicatedStorage")
local rockamount = 1


local function takeDamage(hum, torso, player, damage, power)
	hum:TakeDamage(damage)
	local char = player.Character or player.CharacterAdded:Wait()
	local facepart = char:FindFirstChild("FacePart")
	local knockback = Instance.new("BodyVelocity")
	knockback.Velocity = facepart.CFrame.LookVector * power
	knockback.P = 5000
	knockback.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
	knockback.Parent = torso
	task.wait(0.1)
	knockback:Destroy()
end

local function ontouched(player, power, damage, speed, hitbox, cooldown)
	cooldown.Value = true
	hitbox.CanCollide = true
	local touchedConn = hitbox.Touched:Connect(function(part)
		for i, currentplayer in pairs(game.Players:GetPlayers()) do
			if part.Parent.Name == currentplayer.Name and cooldown.Value == false then
				cooldown.Value = true
				local rockcoins = player.leaderstats.rockcoins
				rockcoins.Value = rockcoins.Value + rockamount
				local hum = part.Parent:FindFirstChild("Humanoid")
				local torso = part.Parent:FindFirstChild("Torso")
				if hum and torso and hum.Health > 0 then
					takeDamage(hum, torso, player, damage, power)
				end
			end
		end
		task.wait(speed)
		hitbox.CanCollide = false
		cooldown.Value = false
	end)
	touchedConn:Disconnect()
end


rs.hitboxevent.OnServerEvent:Connect(ontouched)

Also here’s the another script where the rock’s parent doesnt get set to parent

Server script:

local rs = game:GetService("ReplicatedStorage")


game.Players.PlayerAdded:Connect(function(plr)
	local rock = Instance.new("StringValue")
	rock.Name = "rock"
	rock.Value = "default"
	rock.Parent = plr:WaitForChild("leaderstats")
end)

local changeconn = nil

task.spawn(function()
	while task.wait() do
		for _, player in pairs(game.Players:GetPlayers()) do
			local rock = player:WaitForChild("leaderstats").rock
			local therock = rock.Name.." rock"
			rock.Changed:Connect(function()
				for _, currentrock in pairs(game.ServerStorage.rocks:GetChildren()) do
					if currentrock.Name == therock then
						local char = player.Character or player.CharacterAdded:Wait()
						for _, delete in pairs(char:GetChildren()) do
							if delete.Name ~= therock and delete:IsA("Tool") then
								delete:Destroy()
							end
						end
						
						for _, delete2 in pairs(player.Backpack:GetChildren()) do
							if delete2.Name ~= therock and delete2:IsA("Tool") then
								delete2:Destroy()
							end
						end
						
						for _, delete3 in pairs(game.StarterPack:GetChildren()) do
							if delete3.Name ~= therock and delete3:IsA("Tool") then
								delete3:Destroy()
							end
						end
						
						local clonedtool = currentrock:Clone()
						clonedtool.Parent = player.Backpack
						local clonedtool2 = currentrock:Clone()
						rs.starterpack2:FireClient(player, clonedtool2)
						
					end
				end
			end)
		end
	end
end)


for i, v in pairs(workspace.spawn.stands:GetChildren()) do
	-- spawns
	v:FindFirstChild("ClickDetector").MouseClick:Connect(function(plr)
		-- clickdetector event
		if v:GetAttribute("price") <= plr:FindFirstChild("leaderstats").rockcoins.Value then
			-- if price smaller than rockcoins amount
			plr:FindFirstChild("leaderstats").rock.Value = v.Name
			for _, tool in pairs(game.ServerStorage.rocks:GetChildren()) do
				--all items in game
				if v:GetAttribute("rock") == tool.Name then
					-- if item name is the same
					for _, starterpack in pairs(game.StarterPack:GetChildren()) do
						--starterpack item
						starterpack:Destroy()
					end
					
					for _, deletetool in pairs(plr.Backpack:GetChildren()) do
						for _, startergui in pairs(game.StarterGui:GetChildren()) do
							startergui:Destroy()
						end
						-- tool that needs to be deleted
						if deletetool:IsA("Tool") then
							--if tool is in backpack
							deletetool:Destroy()
						else
							for _, thedeletetool in pairs(plr.Character:GetChildren()) do
								--if tool is in character
								if deletetool:IsA("Tool") then
									deletetool:Destroy()
								end
							end
						end
					end
					local backpack = plr.Character or plr.Backpack
					local backpackprob = plr.Backpack
					local clonedtool = tool:Clone()
					local anotherclonedtool = tool:Clone()
					clonedtool.Parent = plr.Backpack
					rs.starterpack2:FireClient(plr, anotherclonedtool)
				end
			end
		end
	end)
end

and local scripts

local rs = game:GetService("ReplicatedStorage")

rs.starterpack.OnClientEvent:Connect(function(tool)

tool.Parent = game.StarterPack

end)
local rs = game:GetService("ReplicatedStorage")

rs.starterpack2.OnClientEvent:Connect(function(tool)

tool.Parent = game.StarterPack

end)

Thanks.

Don’t use boolvalues for cooldown, use CS or Attributes.

local rs = game:GetService("ReplicatedStorage")
local cs = game:GetService("CollectionService")
local rockamount = 1
function check(pl)
	return cs:HasTag(pl, "CD")
end

local function takeDamage(hum, torso, player, damage, power)
	hum:TakeDamage(damage)
	local char = player.Character or player.CharacterAdded:Wait()
	local facepart = char:FindFirstChild("FacePart")
	local knockback = Instance.new("BodyVelocity")
	knockback.Velocity = facepart.CFrame.LookVector * power
	knockback.P = 5000
	knockback.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
	knockback.Parent = torso
	task.wait(0.1)
	knockback:Destroy()
end

local function ontouched(player, power, damage, speed, hitbox, cooldown)
	cs:AddTag(player, "CD")
	hitbox.CanCollide = true
	local touchedConn = hitbox.Touched:Connect(function(part)
		for i, currentplayer in pairs(game.Players:GetPlayers()) do
			if part.Parent.Name == currentplayer.Name and not check(player) then
				cooldown.Value = true
				local rockcoins = player.leaderstats.rockcoins
				rockcoins.Value = rockcoins.Value + rockamount
				local hum = part.Parent:FindFirstChild("Humanoid")
				local torso = part.Parent:FindFirstChild("Torso")
				if hum and torso and hum.Health > 0 then
					takeDamage(hum, torso, player, damage, power)
				end
			end
		end
		task.wait(speed)
		hitbox.CanCollide = false
		cs:RemoveTag(player, "CD")
	end)
	touchedConn:Disconnect()
end


rs.hitboxevent.OnServerEvent:Connect(ontouched)

And don’t clone tools to backpack on client.

What is CS? I never heard about that

CollectionService

Add a new variable that holds the cooldown boolean. In the function you want it to cooldown, check in the beginning of the function if the cooldown value is true, if it is then return (do nothing). Otherwise just keep going. At the end of the function make the cooldown value true, or at least make the cooldown value true wherever you want the script to start cooldown. Then task.wait as much as you want, then make the cooldown value to false.

local cooldown = false

function cooldownShowcase()
       if cooldown then return end
       
       --script
       
       cooldown = true
       task.wait(as much as you want to wait)
       cooldown = false
end

Oh, im gonna read about it later, thanks, what about the 2nd script?

Just do it on server instead.

So using the object values is a bad idea?

Not a bad idea, it’s just there are much better options.

Okay, is CS better than attritubes then? (sorry for bad grammar)

Oh also forgot to say, i cant put the starterpack tools in starterpack using server because if i do that, everyone will have it in starterpack, and i only need it to be for one player

If it’s just a small thing, then boolvalue should be quick and enough, otherwise collectionService or attributes. Attributes is just a way to store data for that object, collectionService is for tags

the CS tags? I dont rly get it tbh.

They’re universal, object values just cause game cramping and confusing.

so both CS and attitubes good? (again sorry for grammar idk how to spell the attritubes)

Yes.

Thanks, I guess i have to read more in create.roblox

But what about the 2nd script?

@weakroblox35 hello? are you here?

Use StarterGear.