My script should be checking if a player’s name is within the playerTeam folder which is in the teams folder which is in replicated storage. But when it can’t find the player’s name, it just gives an error instead of going to the else statement.
game.ReplicatedStorage.Remotes.InviteToTeam.OnServerEvent:Connect(function(player, playerTeam, playerToInvite)
if game.ReplicatedStorage.Teams[playerTeam][playerToInvite] then
print("Player already in team!")
else
if game.Players[playerToInvite] then
local invitedPlayer = Instance.new("StringValue")
invitedPlayer.Parent = game.ReplicatedStorage.Teams[playerTeam]
invitedPlayer.Name = tostring(playerToInvite)
invitedPlayer.Value = tostring(playerToInvite)
print("Invited!")
end
end
end)