Help with improving sell system

Hello!

I need some help with improving my Sell system. When a Player sells their Swing, they get the same amount of Coins as their Swing. Of course, once they sell, the Swing is reset to zero.

I this script there is also a sell multiplier which I can change so the player can get 2x or 3x more coins. But what I need to improve is adding a cooldown on selling. People have told me that they can overuse the sell by stepping off the sell’s platform and then go back on it quickly whilst they get more Swing. This way, they can get Coins very fast.

Is anyone able to add a cooldown in the script below or create a new script which has a cooldown?

Here’s the Script:

local Part = script.Parent
Part.Touched:Connect(function(HIT)
	local H = HIT.Parent:FindFirstChild("Humanoid")	
	if H then
		local player = game.Players:GetPlayerFromCharacter(HIT.Parent)	
if player then
	local leaderstats = player:WaitForChild("leaderstats")
	local Currency = leaderstats.Coins 
	local Selling = leaderstats.Swing 
		if Selling.Value > 0 then
			Currency.Value = Currency.Value + Selling.Value *1 -- Multiplier
			Selling.Value = 0
		end
end
end
end)

Any help is appreciated, thanks!

1 Like

local Part = script.Parent
local CooldownPlayers = {}
Part.Touched:Connect(function(HIT)
local H = HIT.Parent:FindFirstChild(“Humanoid”)
if H then
local player = game.Players:GetPlayerFromCharacter(HIT.Parent)
if player and not table.find(CooldownPlayers,player) then
table.insert(CooldownPlayers,player)
spawn(function()
wait(CooldownTime)
table.remove(CooldownPlayers,table.find(CooldownPlayers,player))
end)
local leaderstats = player:WaitForChild(“leaderstats”)
local Currency = leaderstats.Coins
local Selling = leaderstats.Swing
if Selling.Value > 0 then
Currency.Value = Currency.Value + Selling.Value *1 – Multiplier
Selling.Value = 0
end
end
end
end)

1 Like