Attempt to index nil issue

So I have this section in my script and for some reason the first time this runs it’s fine, but the next turn this runs I get this error “attempt to index nil with ‘Value’” and not really sure why.

actionEvent.OnServerEvent:Connect(function(player,action,target)
	local battleName = player.Character:FindFirstChild("In Battle").Value --gets the battle from their In Battle tag
	if action == "Attack" then
		activeBattles[battleName].playersInBattle[player.Name].action = "Attack"
		activeBattles[battleName].playersInBattle[player.Name].target = target.Name
		startTurn(battleName)
	elseif action == "Flee" then --makes the player leave the battle and if there's no more players then removes/deletes it
		module.battleLeave(player,battleName)
		leftBattleEvent:FireClient(player)
	end	
end)

I do use :Destroy() on In Battle however it only happens after this runs so I’m not sure what’s nil

Can you tell me which line of code causes the error?

The 2nd line

local battleName = player.Character:FindFirstChild("In Battle").Value

Ah that makes it clear, normal character models doesn’t have In Battle object unless you instance it inside the model. What’s the class name of In Battle?

Are you deleting the Value? if so it is trying to get a value of a deleted object, so it’s nil

Maybe add this in a folder of the player?

I do delete it once the player leaves the battle, but then I create another one whenever they’re in battle again looking in the players character model while running I can clearly see that it’s there so it shouldn’t be nil :s I’ve even tried doing workspace[player.Name]:FindFirstChild("In Battle").Value but I don’t think that did it anything lol

Maybe you are creating the stringvalue on the client, if so create the stringvalue on the server