I am not sure why its doing this

so when a player has 100 or more Gelatine they click a button that should reset their Gelatine value
it does but when they collect something to earn the Gelatine they get the Gelatine value from before back any idea how this can be happening (still learning the basics)

local button = script.Parent
local player = game.Players.LocalPlayer

button.MouseButton1Click:Connect(function()
	if player.leaderstats.Gelatine.Value >=100 then
		player.leaderstats.TimeTravel.Value = player.leaderstats.TimeTravel.Value +1
		player.leaderstats.Gelatine.Value = 0
		player.leaderstats.Gems.Value = player.leaderstats.Gems.Value +1

	if player.leaderstats.Gelatine.Value <=99 then
		end
		end
end)
1 Like
local button = script.Parent
local player = game.Players.LocalPlayer

button.MouseButton1Click:Connect(function()
    if player.leaderstats.Gelatine.Value >= 100 then
        player.leaderstats.TimeTravel.Value += 1
        player.leaderstats.Gelatine.Value = 0
        player.leaderstats.Gems.Value += 1
    else

    end
end)
1 Like

Could you explain it better please, I don’t quite get what you’re saying.

how is this changing anything?

I fixed your code, changed the “end”s and added an “else” I also added “+=“

a person collects objects these object give a currecny called Gelatine and when they have 100 or more they can press a button to reset so 0 Gelatine but when you collect an object again it gives the (100 or the value you had before)

Edit this then. Actually, just remove it. You have nothing in that if statement and you don’t need it.

yea i have changed that but any idea how tha value gets back ?
is it the object the player collects that (breaks) it?

didn’t you read my reply at all??? it has an “else”
also they might need the “else” there for smth, idk what they want to do with the script

Well, give the script of the objects that give you Gelatane.

ready for hell?
well

local db = true

script.Parent.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") ~= nil then
		if db == true then
			db = false
			
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			local TimeTravel = player.leaderstats.TimeTravel.Value 
			local randomx = math.random(-79.502,-19.821)
			local randomz = math.random(187.942,207.703)
			
			if player.leaderstats.TimeTravel.Value ==0 then 
				player.leaderstats.Gelatine.Value = player.leaderstats.Gelatine.Value + 1
				script.Parent.Position = Vector3.new(randomx,14.815,randomz)
				script.Parent.Parent.bear2.Position = Vector3.new(randomx,17.665,randomz-.2)
				wait(.5)
				db = true
			else
				if player.leaderstats.TimeTravel.Value <=1 then 
					player.leaderstats.Gelatine.Value = player.leaderstats.Gelatine.Value + 1 *player.leaderstats.TimeTravel.Value
					script.Parent.Position = Vector3.new(randomx,14.815,randomz)
					script.Parent.Parent.bear2.Position = Vector3.new(randomx,17.665,randomz-.2)
					wait(.5)
					db = true
			   end
			end
		end	
	end
end)

trust me I’ve seen far worse then this

2 Likes

is this code in a local script ?

Why are you multiplying the amount added by timetravel’s value?

local randomx = Random.new():NextNumber(-79.502, -19.821)
local randomz = Random.new():NextNumber(187.942, 207.703)

if you are messing with decimals use that
use math.random() for integers or Random.new():NextInteger() for integers

its not a local script should it be?

yea timetravel is meant to multiply it like 5Gelatine * 2 timetravel

nope, i was just making sure, nvm

so is it because of the object the player collects or not at all?

is there some sort of other value in serverStorage or somewhere that is the actual player gelatine while the one in leaderstats just copys that value ?