Why is :Increment adding more value every time?

I’m trying to make a system where whenever a user touches a part, it adds 100 to their “currency” value, but when a player does it a second time, it gives them 200 more instead of 100, and then when a player does it a third time it gives them 300, and so on. I’ve never experienced this issue before and I’m not sure how to fix it. Could anyone help?

script:

FinishPart.Touched:Connect(function(Touched)
			if Touched.Parent:FindFirstChild("Humanoid") or Touched.Parent.Parent:FindFirstChild("Humanoid") then
				FinishPart.CanTouch = false
				
				local Character = Touched.Parent
				local Player = game:GetService("Players"):GetPlayerFromCharacter(Character)
				wait(1)
				
				local DataStore2 = require(1936396537)
				
				local award = -100
				
				local currencyStore = DataStore2("currency", Player)
				currencyStore:Increment(-award)
				
				ObbyMinigame.Parent = game.ReplicatedStorage
				GameHosted.Value = false
				FinishPart.CanTouch = true
			end
1 Like

why are you subtracting negative 100 and not just adding 100?

also maybe in case “award” is being changed over time, move the “award” definition outside of the touched event

Oh I don’t know why I used -100, it doesn’t change it either way

I tried moving it out the event already and the same thing happened.

well, i could be wrong but
finishpart’s cantouched is set to false, as to not trigger the award again, correct? but then after waiting 1 second, it is set to cantouch true again
so maybe youre actually just triggering it more than once on accident…?

I don’t think that’s it because the value increases by 100 exactly each time, and even if I destroy the part giving the reward after it’s first touched it still does the same thing.

wait so is your call for touching it to give you 100 and then the next time it gives you 200

or is your problem that you want it to always give you 100 but its not doing that and its doing the above thing

I want it to always give me 100 but it doesn’t, it adds 100 to the amount it gives me each time I do it

How do you know it’s giving you 100 more every time? Are you printing the value of the datastore each time it is changed?

It could be that you are printing the value of the datastore each time. In that case, the value of the datastore would go up by 100 each time
ie:

100
200
300

if that’s the case then it just seems like the value is increasing by an additional 100 every time

The value is named currency, and I have a box in the corner of the screen that tells you the amount of currency you have.
image

1 Like

So it goes up like this?

100
300
600
1 Like

Yeah, it does go up just like that. I’ve tried re-writing the script in different ways, using an IntValue, using RemoteEvents, nothing’s stopped this

1 Like

Is the Touched event inside anything?
For example:

game.Players.PlayerAdded:Connect(function(player)
    FinishPart.Touched:Connect(function(Touched)

That’s it. I had it inside a RemoteEvent. I’ve got it working now, thanks a bunch

1 Like

Glad to be of help :slight_smile:

i dont like limits

1 Like