How can I fix this?

How can I fix this error?
Screenshot 2023-01-28 170822

Add a debounce to your script.

Is there another way to do it? I’m making a level system and when I get the player more than 1000 xp it give the error a debounce would mess it up, i think :confused:

You can make a connection and then disconnect it.

By this do you mean give the xp in increments?

No, like a connection with a function, ex:

local connection
for _,v in pairs(workspace:GetChildren()) do
     if v:IsA("Part") then
             connection = Part.Touched:Connect(function(hit) print(hit.Name) end)
              task.wait(5)
               connection:Disconnect()
      end
end

This makes it so I cant even add 100 xp
my code:

	local connection
	
	XP:GetPropertyChangedSignal("Value"):Connect(function(NewXP)
		connection = function ()
			if XP.Value >= NeededXP.Value then
				local LeftOverXP = XP.Value - NeededXP.Value
				XP.Value = 0
				if LeftOverXP ~= 0 then
					XP.Value = LeftOverXP
				end
				rank.Value += 1
				NeededXP.Value = rank.Value * 50
				wait(0.1)
			end
		end
		connection:Disconnect()
end)

Well, that wouldn’t really work. Try searching the solution to this problem up.

I just relized I get this

  17:22:11.495  ServerScriptService.Player:65: attempt to index function with 'Disconnect'  -  Server - Player:65
  17:22:11.495  Stack Begin  -  Studio
  17:22:11.495  Script 'ServerScriptService.Player', Line 65  -  Studio - Player:65
  17:22:11.495  Stack End  -  Studio

Connections dont work with function().

I suggest looking at this post: