my multiplier is not working and isTouched (Debounce) check for waiting time is not working also… does anyone know what is wrong?
I have created this in the player:

my localscript at startergui:
local player = game.Players.LocalPlayer
local gemButton = script.Parent
local gems = player.leaderstats.Gems
print(gems.Value)
local function multiplierGems()
local isTouched = false
if not isTouched then
print('You have entered the function')
isTouched = true
task.wait(5)
isTouched = false
print('You have left the function')
gems = gems.Value * 2
end
end
gemButton.MouseButton1Click:Connect(function()
print('gems button has been clicked!')
multiplierGems()
end)
my leaderstats script → ServerScriptService:
local DataStoreService = game:GetService("DataStoreService")
local playerGemsData = DataStoreService:GetDataStore("gemsDataStore")
function saveData(player, dataToStore)
local tableToSave = {
player.leaderstats.Gems.Value
}
local success, errorMessage = pcall(function()
playerGemsData:SetAsync(player.UserId, tableToSave)
end)
if success then
warn('The gems has been saved')
else
print('DataStore error! something went wrong.')
warn(errorMessage)
end
end
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new('Folder')
leaderstats.Name = 'leaderstats'
leaderstats.Parent = plr
local gems = Instance.new('IntValue')
gems.Name = 'Gems'
gems.Parent = leaderstats
local data
local success, errorMessage = pcall(function()
data = playerGemsData:GetAsync(plr.UserId)
end)
if success then
gems.Value = data[0]
print(data[0])
print(gems.Value)
else
print('The player has not data')
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
saveData(plr)
end)
game:BindToClose(function()
for _, bindToClose_Player in pairs(game.Players:GetPlayers()) do
saveData(bindToClose_Player)
end
end)
