Remote event fires more every time?!

I am a grass patch just like the pokemon games, and each time the player steps on the grass, it makes a random number. If both of them is 1, and the player is ready, the remote event will fire. This is my script:

local a
local b
script.Parent.Touched:connect(function(toucher)
	if game.Players:FindFirstChild(toucher.Parent.Name) then
		local p = game.Players:FindFirstChild(toucher.Parent.Name)
		local t = game.ReplicatedStorage:FindFirstChild(toucher.Parent.Name).Items
			a = math.random(1,50) 
				if a == 1 then
					p.Character.Head.Anchored = true
				local f = Instance.new('Vector3Value', p.PlayerInfo)
			f.Value = toucher.Parent.HumanoidRootPart.Position print(f.Value)
			print(p.PlayerGui.BattleReady.LocalScript.Disabled)
				p.PlayerGui.BattleReady.LocalScript.Disabled = false print(p.PlayerGui.BattleReady.LocalScript.Disabled)
			toucher.Parent.Head.CFrame = workspace.BattleCamera.CFrame+Vector3.new(0,5,0)
			game.ReplicatedStorage.Battle.Ready.OnServerEvent:Connect(function()
b = math.random(1,1)
				if b == 1 then
					wait()
					game.ReplicatedStorage.MonBattle.Mon10:FireClient(p) print('checking')
end b = 0 end) a = 0 end end end)

The funny thing is this print('checking'). I added this to check. I found out the first time, it prints once and the remote event fires once. The second time, it prints twice and the remote event fires twice and so on.

First Time

Unt1itled

Second Time

Unt1itled

Sorry if my scripts look bad and unorganized. I also have some random prints that I forgot to delete.

When your battle ready, what stops you from having a battle again if someone touches it (just saying as you’ll now be hit with constant battles)?

Also your issue is your OnServerEvent is inside the touch event, meaning that every time the player touches it another event is added. Move it outside the touched function and then it will only spawn the event once.

Also the editor tidies code automatically for you - you might find it beneficial if you use it. Here is a formatted code for you with the fixture:

local a
local b

script.Parent.Touched:connect(function(toucher)
	if game.Players:FindFirstChild(toucher.Parent.Name) then
		local p = game.Players:FindFirstChild(toucher.Parent.Name)
		local t = game.ReplicatedStorage:FindFirstChild(toucher.Parent.Name).Items
		a = math.random(1,50)
		if a == 1 then
			p.Character.Head.Anchored = true
			local f = Instance.new('Vector3Value', p.PlayerInfo)
			f.Value = toucher.Parent.HumanoidRootPart.Position
			
			print(f.Value)
			print(p.PlayerGui.BattleReady.LocalScript.Disabled)
			
			p.PlayerGui.BattleReady.LocalScript.Disabled = false print(p.PlayerGui.BattleReady.LocalScript.Disabled)
			toucher.Parent.Head.CFrame = workspace.BattleCamera.CFrame+Vector3.new(0,5,0)
		end
		a = 0 -- irrelevant, you can remove
	end
end)

-- I would move this to its own script in ServerScriptService so you don't have to create it in every grass block
game.ReplicatedStorage.Battle.Ready.OnServerEvent:Connect(function(p)
	b = math.random(1,1)
	if b == 1 then
		wait()
		game.ReplicatedStorage.MonBattle.Mon10:FireClient(p)
		print('checking')
	end
	b = 0 -- irrelevant, you can remove
end)

Thanks! I will try it soon and mark your answer as a solution if it works!