Hi! So I got a screen and a button the screen has a value called MoneySaved and when the button is pressed by a player that value changes to be the leaderstats value and resets itself. But when it resets itself it makes the leaderstats resets itself too. here is the script: (debounce added also)

local button = script.Parent
local debounce = false
button.Touched:Connect(function(hit)
	debounce = true
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if not player then return end
		if player then
			if player.Team.Name == "Red" then
				
				 player.leaderstats.Money.Value = button.Parent.Screen.MoneySaved.Value
				button.Parent.Screen.MoneySaved.Value = 0
				
				button.BrickColor = BrickColor.new("Really red")
				wait(2)
				button.BrickColor = BrickColor.new("Sea green")
				wait(2)
				debounce = false
			end
		end
	end
end)

1 comment

0

Have you used DataStoreService?