My multiplier is not working help

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:

image

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)

in here, you should set gems.Value instead of just gems

like this?
gems.Value = gems.Value * 2
I tried like this and it still does not work … I am doing this in a localscript from the gui

image

when you tried it, did it show any error?

None, the function is performed, like normal…

Ademas del error que indico @TheLordGamer1820, isTouched debe estar fuera de la función

local player = game:GetService("Players").LocalPlayer
local gemButton = script.Parent
local gems = player.leaderstats.Gems

print(gems.Value)

local isTouched = false
gemButton.MouseButton1Click:Connect(function()
	print('gems button has been clicked!')
	if not isTouched then
		print('You have entered the function')
		isTouched = true
		task.wait(5)
		isTouched = false
		print('You have left the function')
		gems.Value *= 2
	end
end)

si los cambios deben ser visibles desde el servidor, usa un RemoteEvent para cambiar el valor.

2 Likes

oh, yes. value in the server would not be updated since you used local script. so what you need to do is use remote events just like @SOTR654 said. oh and also, your debounce wont work since you set it to false everytime you run the function. to fix it, instead of doing this

do this instead,

local isTouched = false
local function multiplierGems()